generated from nhcarrigan/template
feat: initial prototype works
I can log in and create a book! Woo!
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @copyright 2026 NHCarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import { FastifyInstance } from "fastify";
|
||||
import fastifyStatic from "@fastify/static";
|
||||
import path from "path";
|
||||
|
||||
export default async function staticPlugin(app: FastifyInstance) {
|
||||
const isProduction = process.env.NODE_ENV === "production";
|
||||
|
||||
if (isProduction) {
|
||||
// Serve the built Angular app from dist directory
|
||||
await app.register(fastifyStatic, {
|
||||
root: path.join(__dirname, "../../../../../../dist/apps/frontend"),
|
||||
prefix: "/", // Serve at root
|
||||
wildcard: false, // Disable wildcard routes to avoid conflicts
|
||||
});
|
||||
|
||||
// Catch-all route for Angular SPA routing (must be registered after API routes)
|
||||
app.setNotFoundHandler((request, reply) => {
|
||||
// Only catch routes that don't start with /api
|
||||
if (!request.url.startsWith("/api")) {
|
||||
reply.sendFile("index.html");
|
||||
} else {
|
||||
reply.code(404).send({ error: "Not Found" });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user