Hi, I would like to have an example about serving static folders in Payload. Theses files can be used for instance in admin.meta.favicon
field in payload.config.ts
.
I tried using express.static in my server.ts
as follow but this does not work:
app.use('/public', express.static('assets/public'));
=> give 404 on localhost:3000/public
app.use('/public', express.static(__dirname + '/assets/public'));
=> also give 404 localhost:3000/public
Is there any example/documentation about serving static files in Payload that I can take a look at ? Thanks a lots !
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'));
?
Thanks a lots, (path.resolve()
indeed solves the problem !
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.