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

Configured redirects not working with node adapter (or documentation missing) #11412

Closed
1 task
pReya opened this issue Jul 4, 2024 · 4 comments · Fixed by withastro/docs#8894
Closed
1 task
Assignees
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority) pkg: node Related to Node adapter (scope)

Comments

@pReya
Copy link
Contributor

pReya commented Jul 4, 2024

Astro Info

Astro                    v4.11.4
Node                     v22.1.0
System                   macOS (arm64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/node
Integrations             @astrojs/react
                         @astrojs/tailwind
                         astro-icon
                         astro:db
                         @astrojs/db/file-url

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

No response

Describe the Bug

I have configured redirects in my astro.config.mjs. For these redirects, I have also a static page/astro file that matches the same route. Locally in my dev server, the redirects work and seem to have priority over my .astro file. However they do not work in my live deployment, when using the Node adapter. There it seems that either the redirects are buggy/not generated - or the static page wins over the redirects in terms of priority. Either way, the behavior on prod differs from the behavior on dev. If this is intentional, I wish this was documented somewhere. In general, the documentation for the priority is "configured" redirects is nowhere to be found.

Here is my config:

import { defineConfig } from "astro/config";
import react from "@astrojs/react";
import tailwind from "@astrojs/tailwind";
import icon from "astro-icon";
import db from "@astrojs/db";
import node from "@astrojs/node";

export default defineConfig({
  integrations: [
    react(),
    tailwind({
      applyBaseStyles: false,
    }),
    icon(),
    db(),
  ],
  vite: {
    optimizeDeps: {
      exclude: ["astro:db"],
    },
  },
  output: "server",
  trailingSlash: "never",
  redirects: {
    "/de/admin": "/de/admin/projects",
    "/en/admin": "/en/admin/projects",
  },
  adapter: node({
    mode: "standalone",
  }),
  site: "https://subdomain.apps.myproject.de/",
  experimental: {
    env: {
      schema: {
        [...]
      },
    },
  },
});

Visiting https://subdomain.apps.myproject.de/de/admin will NOT redirect me to https://subdomain.apps.myproject.de/de/admin/projects as intended. Instead, it will serve the static page/astro file, which can be found under /de/admin/index.astro. Maybe this is a priority issue? From the documentation it's not clear to me, who will win, if there is both a configured redirect AND a .astro file/page for the same path. I can't find anything about redirects in the documentation section Route priority order.

What's the expected result?

Redirect should work in Node environment, too.

Link to Minimal Reproducible Example

Can't reproduce completely on Stackblitz, because the behavior is different on the dev server vs deployment via the node adapter. Anyway, here's a Stackblitz: https://stackblitz.com/edit/github-wg2t3j

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 Jul 4, 2024
@pReya pReya changed the title Configured redirects not working with node adapter Configured redirects not working with node adapter (or documentation missing) Jul 4, 2024
@ematipico ematipico added needs repro Issue needs a reproduction and removed needs triage Issue needs to be triaged labels Jul 4, 2024
Copy link
Contributor

github-actions bot commented Jul 4, 2024

Hello @pReya. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs repro will be closed if they have no activity within 3 days.

@ematipico
Copy link
Member

ematipico commented Jul 4, 2024

Hey @pReya, even if the repro doesn't work in stackblitz, please create a stackblitz so we can download it and test it locally.

@pReya
Copy link
Contributor Author

pReya commented Jul 4, 2024

Hey @pReya, even if the repro doesn't work in stackblitz, please create a stackblitz so we can download it and test it locally.

Added one in the opening post.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 8, 2024
@ematipico ematipico reopened this Jul 8, 2024
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jul 8, 2024
@ematipico ematipico removed the needs repro Issue needs a reproduction label Jul 8, 2024
@Princesseuh Princesseuh added pkg: node Related to Node adapter (scope) - P4: important Violate documented behavior or significantly impacts performance (priority) and removed needs triage Issue needs to be triaged labels Jul 17, 2024
@ematipico ematipico self-assigned this Jul 19, 2024
@ematipico
Copy link
Member

It seems to be a bug in our documentation. I will raise a PR to address that. The routing priority favours the file system, and in this case /admin is rendered because there's a page in the file system.

Here's the initial proposal: https://github.com/withastro/roadmap/blob/main/proposals/0041-redirects.md#routing-priority

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority) pkg: node Related to Node adapter (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants