generated from nhcarrigan/template
fix: allow static assets to be served correctly
Fixed the not-found handler to exclude /assets routes, allowing static assets like images to be served with correct MIME types instead of being caught by the SPA fallback handler. Changes: - Updated setNotFoundHandler to check for /assets prefix - Assets are now served directly by fastify-static with correct content-type - Only non-API, non-asset routes fall through to index.html This fixes the default cover image not displaying because it was being served as text/html instead of image/jpeg. Co-Authored-By: Naomi Carrigan <commits@nhcarrigan.com>
This commit is contained in:
@@ -21,8 +21,8 @@ export default async function staticPlugin(app: FastifyInstance) {
|
|||||||
|
|
||||||
// Catch-all route for Angular SPA routing (must be registered after API routes)
|
// Catch-all route for Angular SPA routing (must be registered after API routes)
|
||||||
app.setNotFoundHandler((request, reply) => {
|
app.setNotFoundHandler((request, reply) => {
|
||||||
// Only catch routes that don't start with /api
|
// Only catch routes that don't start with /api or /assets
|
||||||
if (!request.url.startsWith("/api")) {
|
if (!request.url.startsWith("/api") && !request.url.startsWith("/assets")) {
|
||||||
reply.sendFile("index.html");
|
reply.sendFile("index.html");
|
||||||
} else {
|
} else {
|
||||||
reply.code(404).send({ error: "Not Found" });
|
reply.code(404).send({ error: "Not Found" });
|
||||||
|
|||||||
Reference in New Issue
Block a user