Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does the fastify-nextjs public folder not work as designed by NextJS? #725

Open
2 tasks done
matthewgisonno opened this issue Apr 5, 2023 · 3 comments
Open
2 tasks done

Comments

@matthewgisonno
Copy link

matthewgisonno commented Apr 5, 2023

Prerequisites

  • I have written a descriptive issue title
  • 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?

@mcollina
Copy link
Member

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".

@alexandrucancescu
Copy link
Contributor

@matthewgisonno Did you find a solution for this? Currently struggling with the same issue?

@brandonxiang
Copy link

@matthewgisonno I use fastify/static for public resources

fastify.register(require('@fastify/static'), {
  root: path.join(__dirname, 'public'),
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants