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

custom status code does not seem to be respected in configured redirects #9568

Closed
1 task
JulioGrajales opened this issue Jan 2, 2024 · 6 comments · Fixed by #9657
Closed
1 task

custom status code does not seem to be respected in configured redirects #9568

JulioGrajales opened this issue Jan 2, 2024 · 6 comments · Fixed by #9657
Assignees
Labels
feat: redirects Related to the redirects feature (scope) needs triage Issue needs to be triaged

Comments

@JulioGrajales
Copy link

Astro Info

Astro                    v4.0.8
Node                     v21.5.0
System                   Windows (x64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/node
Integrations             @astrojs/tailwind
                         @astrojs/svelte

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Configured redirects don't seem to respect a custom status code when provided using an object. using the following configuration:

redirects: {
    '/hello': {
      status: 302,
      destination: '/other',
    },
  },

does not use 302 status code and instead uses 301 status code (the default). I'm in SSR mode, using node adapter.
redirect-astro

What's the expected result?

It should redirect me using 302 status code or any other valid custom status code provided in the configured redirect object.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-9cfd3y?file=astro.config.mjs

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jan 2, 2024
@florian-lefebvre florian-lefebvre added feat: redirects Related to the redirects feature (scope) - P4: important Violate documented behavior or significantly impacts performance (priority) and removed needs triage Issue needs to be triaged labels Jan 2, 2024
@florian-lefebvre
Copy link
Member

florian-lefebvre commented Jan 4, 2024

An interesting thing to check would be to see if it's node specific or if it also happens with other adapters like vercel

@ematipico
Copy link
Member

An interesting thing to check would be to see if it's node specific or if it also happens with other adapters like vercel

I can replicate it in dev using the stackblitz example, so it's probably an issue in core

@Runeloon
Copy link

Appears this fix doesn't work in the latest 4.2.4 release. Bit difficult to work out why, as the create.ts appears to have gone through a bit of a rework.
Have verified at least that upon hitting redirectRouteStatus, the redirectRoute.redirectRoute property is null, meaning it never bothers checking the redirectRoute.redirect.status, which is set.
Testing example of input to redirectRouteStatus in 4.2.4:
{ type: 'redirect', isIndex: false, route: '/test1', pattern: /^\/test1\/?$/, segments: [ [ [Object] ] ], params: [], component: '/test1', generate: [Function (anonymous)], pathname: '/test1', prerender: false, redirect: { status: 302, destination: '/test2' }, redirectRoute: undefined, fallbackRoutes: [] }

@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jan 25, 2024
@ematipico
Copy link
Member

@Runeloon can you provide a reproduction?

@ematipico ematipico removed the - P4: important Violate documented behavior or significantly impacts performance (priority) label Jan 25, 2024
@lilnasy
Copy link
Contributor

lilnasy commented Jan 26, 2024

The reproduction provided here behaves as expected now. If there's still a case where it doesn't work, it would be a distinct issue.

@lilnasy lilnasy closed this as completed Jan 26, 2024
@JulioGrajales
Copy link
Author

I did some tests myself and discovered a strange behavior.

Astro info:

Astro                    v4.2.5
Node                     v21.6.1
System                   Windows (x64)
Package Manager          pnpm
Output                   server
Adapter                  @astrojs/node
Integrations             none

there is apparently a difference in behavior depending on whether you add a trailing slash ( / ) to the destination property of the configured redirect object or not.

no trailing slash:

astro.config.mjs:

import { defineConfig } from 'astro/config';

// https://astro.build/config
export default defineConfig({
  redirects: {
    '/hello': {
      status: 302,
      destination: '/other',
    },
  },
});

no_trailing

trailing slash:

astro.config.mjs:

import { defineConfig } from 'astro/config';

// https://astro.build/config
export default defineConfig({
  redirects: {
    '/hello': {
      status: 302,
      destination: '/other/',
    },
  },
});

trailing

Reproduction:
https://stackblitz.com/edit/github-paatym?file=astro.config.mjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: redirects Related to the redirects feature (scope) needs triage Issue needs to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants