In my Astro site one of the routes is routing to localhost

Hello. I am trying to move my Astro site from Vercel, where it is currently working without problems (except for some bug in the Vercel integration that makes impossible to build static pages) to railway. I created a docker image and managed to make it build properly. The site is deployed and available, but for some weird reason one of the routes that points to a static path is redirecting me to localhost. When I click the link first I see a white screen saying that I will be redirected to localhost, and them I am redirected to localhost. Any idea why? Is this something Railway load balancer does?
42 Replies
Percy
Percy7mo ago
Project ID: c2147d2a-2ed6-4234-b48a-50d16f81e68c
danielo515
danielo5157mo ago
c2147d2a-2ed6-4234-b48a-50d16f81e68c
maddsua
maddsua7mo ago
Hey! Mind sharing a link? It doesn't look like something that neither Astro or Railway usually do
danielo515
danielo5157mo ago
Boda de Ali y Dani
Boda de Alicia y danielo
danielo515
danielo5157mo ago
By the way, I fixed the redirect by providing the public url of the site to Astro, so at least it now redirects to the right place When testing this inside docker in my local machine accessing that url makes the server crash, which is why I assume the redirect happens
Brody
Brody7mo ago
vercel will automatically intercept redirects to localhost and change them to redirect to the public address, railway will not do anything of the sort, when running on railway your code must send the correct redirect response
danielo515
danielo5157mo ago
The app does not crash on Vercel, and no redirect happens, the right route is displayed On railway there are no logs when I hit that route wich make me suspect the app crashes, and as I mentioned in docker in my local machine it crash Tried different versions of docker node and all crash the same way Running as a node server (no docker) everything works fine
Brody
Brody7mo ago
let's see your dockerfile
danielo515
danielo5157mo ago
FROM node:18-slim AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
COPY . /app
COPY astro.node.config.ts /app/astro.config.ts
WORKDIR /app

FROM base AS prod-deps
RUN --mount=type=cache,id=s/0cdba51f-ca18-4991-b228-f30672040b04-pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile

FROM base AS build
ARG POSTGRES_URL
ARG SITE_URL
RUN --mount=type=cache,id=s/0cdba51f-ca18-4991-b228-f30672040b04-pnpm,target=/pnpm/store pnpm install --frozen-lockfile
RUN pnpm run build

FROM base
COPY --from=prod-deps /app/node_modules /app/node_modules
COPY --from=build /app/dist /app/dist

ENV HOST=0.0.0.0
ENV PORT=4321
EXPOSE 4321
CMD node ./dist/server/entry.mjs
FROM node:18-slim AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
COPY . /app
COPY astro.node.config.ts /app/astro.config.ts
WORKDIR /app

FROM base AS prod-deps
RUN --mount=type=cache,id=s/0cdba51f-ca18-4991-b228-f30672040b04-pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile

FROM base AS build
ARG POSTGRES_URL
ARG SITE_URL
RUN --mount=type=cache,id=s/0cdba51f-ca18-4991-b228-f30672040b04-pnpm,target=/pnpm/store pnpm install --frozen-lockfile
RUN pnpm run build

FROM base
COPY --from=prod-deps /app/node_modules /app/node_modules
COPY --from=build /app/dist /app/dist

ENV HOST=0.0.0.0
ENV PORT=4321
EXPOSE 4321
CMD node ./dist/server/entry.mjs
Brody
Brody7mo ago
i see you are doing a whole lot of stuff that isnt absolutely necessary, please get a minimal dockerfile working first
maddsua
maddsua7mo ago
wait do you really need a dockerfile to make astro work on railway?
Brody
Brody7mo ago
no no
danielo515
danielo5157mo ago
I was using a dockerfiie for portability in case I want to go another place. But will try without a dockerfiie How do I force it to be a node server? It automatically detects the dockerfiie and uses it
Brody
Brody7mo ago
remove or rename the dockerfile
danielo515
danielo5157mo ago
I changed to custom build and run commands. Does that suffice ? The problem persists
Want results from more Discord servers?
Add your server