fastify-nextjs
fastify-nextjs copied to clipboard
Does the fastify-nextjs public folder not work as designed by NextJS?
Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the issue has not already been raised
Issue
Maybe I am misinterpreting how this all comes together, but I am using the fastify-nextjs
plugin to serve pages from the /src/pages
folder... Example: /src/pages/payment-options.js
with a route defined like so:
await app.register(fastifyNextJs).after(async () => {
await app.next('/payment-options');
});
That route works fine... That said, I tried creating a public
folder at the root of my project as is allowed by NextJS for serving static assets (html, css, js, text, images, etc) and I cannot access the URL via a web browser.
created file:
/public/styles.css
Tried to access via browser at http://localhost/styles.css
and I get the standard fastify route doesn't exist 404 error...
{"message":"Route GET:/styles.css not found","error":"Not Found","statusCode":404}
in the browser.
Does the fastify-nextjs
not allow the nextjs public
folder to work like it does in a normal nextjs setup?
Thanks for reporting!
Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.
Take a look at the part of the docs that mention "assets serving".
@matthewgisonno Did you find a solution for this? Currently struggling with the same issue?
@matthewgisonno I use fastify/static for public resources
fastify.register(require('@fastify/static'), {
root: path.join(__dirname, 'public'),
});