Rewrites not working for files in public/
Issue Summary
When using a Next.js rewrite for a destination inside public/, it will not work and instead return the Next.js 404 page.
Actual behavior
Rewriting a source path /test to a destination path /test.html, when public/test.html exists, will return the Next.js 404 page.
Expected behavior
Rewriting a source path /test to a destination path /test.html will return the static file located at public/test.html
Steps to reproduce
- Add a file
public/test.html - Add the rewrite to
next.config.js:rewrites: async () => [ { source: '/test', destination: '/test.html' }, ], - open
<url>/test.htmland it works - open
<url>/testand it does not work!
Screenshots/Code/Configuration/Logs
I have setup such a case on my own static site for demonstration:
- https://iiro.fi/favicon doesn't work
- https://iiro.fi/favicon.ico does work
-
next.config.jsis here: https://github.com/iiroj/iiro.fi/blob/master/site/next.config.js#L18
Versions
- OS/Environment: GitHub CI
ubuntu-latest - @sls-next/serverless-component version:
3.6.0 - Next.js version:
12.0.7
Additional context
Checklist
- [ ] You have reviewed the README and FAQs, which answers several common questions.
- [ ] You have reviewed our DEBUGGING wiki and have tried your best to include complete information and reproduction steps (including your configuration) as is possible. As there is only one maintainer (who maintains this in his free time) and thus very limited resources, if you have time, please try to debug the issue a bit yourself if possible.
- [ ] You have first tried using the most recent
latestoralpha@sls-next/serverless-componentrelease version, which may have already fixed your issue or implemented the feature you are trying to use. Note that the oldserverless-next.jscomponent and theserverless-next.jsplugin are deprecated and no longer maintained.
@iiroj Hey! I have the exact same problem, did you manage to find a way to make it work?
same here... not working // even with "beforeFiles"
/** @type {import('next').NextConfig} */ module.exports = { reactStrictMode: true, i18n: { locales: ['en', 'cs'], defaultLocale: 'en' }, async rewrites() {
return [
{
source: "/admin",
destination: "/admin/index.html"
// destination:
// process.env.NODE_ENV === "development"
// ? "http://localhost:3333/admin/:path*"
// : "/admin/index.html"}
},
{
source: '/admin/:path*',
destination: '/admin/index.html'
}
]
}
}
exactly same problem with the latest version of Nextjs
if the rewrites have locale false, they do not work either
@iiroj Hey! I have the exact same problem, did you manage to find a way to make it work?
i ended up putting the html on a cdn and referencing the full-path URL as the destination as a work around
Any updates on that?