Skip to content

Serving static assets #686

Answered by DanRibbens
henrituan asked this question in Q&A
Jun 25, 2022 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

This is really an express question more than to do with Payload.

When you say you get a 404 from localhost:3000/public are you specifying the file too as in localhost:3000/public/favicon.ico? The expected result for hitting just the directory path is a 404 unless you have a handler set also.

Assuming that you are requesting files it has to be a problem with how you are calling express.static. We use path.resolve(__dirname, './assets/public') rather than + to concat path names together.

What happens if you try app.use('/public', express.static(path.resolve(__dirname, './assets/public'));?

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@henrituan
Comment options

Answer selected by henrituan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants