serverless-next.js icon indicating copy to clipboard operation
serverless-next.js copied to clipboard

Rewrites not working for files in public/

Open iiroj opened this issue 4 years ago • 5 comments

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

  1. Add a file public/test.html
  2. Add the rewrite to next.config.js:
       rewrites: async () => [
         { source: '/test', destination: '/test.html' },
       ],
    
  3. open <url>/test.html and it works
  4. open <url>/test and 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.js is 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 latest or alpha @sls-next/serverless-component release version, which may have already fixed your issue or implemented the feature you are trying to use. Note that the old serverless-next.js component and the serverless-next.js plugin are deprecated and no longer maintained.

iiroj avatar Jan 07 '22 19:01 iiroj

@iiroj Hey! I have the exact same problem, did you manage to find a way to make it work?

vivian8910 avatar Apr 04 '22 17:04 vivian8910

same here... not working // even with "beforeFiles"

IPv6 avatar Jun 07 '22 14:06 IPv6

/** @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

Marcel-Konjata avatar Aug 05 '22 10:08 Marcel-Konjata

@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

abomblabrom avatar Oct 01 '22 01:10 abomblabrom

Any updates on that?

denyskotsur avatar Sep 08 '23 04:09 denyskotsur