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

routeRules does not work in DEV mode for static files #2749

Open
xak2000 opened this issue Sep 23, 2024 · 0 comments · May be fixed by #2814
Open

routeRules does not work in DEV mode for static files #2749

xak2000 opened this issue Sep 23, 2024 · 0 comments · May be fixed by #2814

Comments

@xak2000
Copy link

xak2000 commented Sep 23, 2024

Environment

Node Version: v18.20.3
Nitro Version: 2.9.7

Reproduction

In this example /hello.txt route should return Content-type: application/json header, and it does work in the PROD mode, but doesn't work in the DEV mode, where Content-type: text/plain; charset=UTF-8 is returned.

Try to access /hello.txt route and check the headers of the response:

  1. In DEV mode.
  2. In PROD mode.

public/hello.txt

World

nitro.config.ts

// https://nitro.unjs.io/config
export default defineNitroConfig({
  srcDir: 'server',
  routeRules: {
    '/hello.txt': {
      headers: {
        'Content-Type': 'application/json',
      },
    },
  },
});

Describe the bug

When nitro.config.ts contains a routeRules section that sets headers for a static file (from public dir), then these headers are not set when the server is running in DEV mode (npm run dev). The headers are set, though, when the server is running in PROD mode (npm run build && npm run preview).

Additional context

The bug was originally created as nuxt/nuxt#26740.

Logs

No response

peterthenelson added a commit to peterthenelson/nitro-asset-route-rules that referenced this issue Oct 25, 2024
- These otherwise fail to be applied to public
  assets (see nitrojs#2749).
- This change replies them redundantly in the
  other cases (where they were already being
  applied), but the alternative would require
  duplicating or reversing the URL / file path
  logic from the "send" package.

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

Successfully merging a pull request may close this issue.

1 participant