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

Anonymous
TRIAL

a year ago

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?

0 Replies

Anonymous
TRIAL

a year ago

c2147d2a-2ed6-4234-b48a-50d16f81e68c


maddsua
HOBBY

a year ago

Hey! Mind sharing a link? It doesn't look like something that neither Astro or Railway usually do


Anonymous
TRIAL

a year ago


Anonymous
TRIAL

a year 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


Anonymous
TRIAL

a year ago

When testing this inside docker in my local machine accessing that url makes the server crash, which is why I assume the redirect happens


a year 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


Anonymous
TRIAL

a year ago

The app does not crash on Vercel, and no redirect happens, the right route is displayed


Anonymous
TRIAL

a year ago

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


Anonymous
TRIAL

a year ago

Tried different versions of docker node and all crash the same way


Anonymous
TRIAL

a year ago

Running as a node server (no docker) everything works fine


a year ago

let's see your dockerfile


Anonymous
TRIAL

a year 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

a year ago

i see you are doing a whole lot of stuff that isnt absolutely necessary, please get a minimal dockerfile working first


maddsua
HOBBY

a year ago

wait do you really need a dockerfile to make astro work on railway?


a year ago

no


a year ago

no


Anonymous
TRIAL

a year ago

I was using a dockerfiie for portability in case I want to go another place. But will try without a dockerfiie


Anonymous
TRIAL

a year ago

How do I force it to be a node server? It automatically detects the dockerfiie and uses it


a year ago

remove or rename the dockerfile


Anonymous
TRIAL

a year ago

I changed to custom build and run commands. Does that suffice ? The problem persists


a year ago

what are your custom build and start commands?


Anonymous
TRIAL

a year ago

Just removed the dockerfile. The build now fails.
My custom build is:
pnpm build
My custom run is
node ./dist/server/entry.mjs
Now that I removed the dockerfile it fails to build:

15.05 [commonjs--resolver] Failed to resolve entry for package "flowbite-svelte". The package may have incorrect main/module/exports specified in its package.json: No known conditions for "." specifier in "flowbite-svelte" package

a year ago

full build logs please


Anonymous
TRIAL

a year ago

Maybe I need to run pnpm install first? Or does that happen automatically?


a year ago

fix your typo please, i dont understand the question


Anonymous
TRIAL

a year ago

wow, chrome made having bookmarklets very difficult


Anonymous
TRIAL

a year ago


a year ago

its just drag and drop?


a year ago

i use chrome


a year ago

remove the install command from your build command please


Anonymous
TRIAL

a year ago

Removed, do I re-export the logs?


a year ago

yes please


Anonymous
TRIAL

a year ago


a year ago

what node version are you using locally


Anonymous
TRIAL

a year ago

18


Anonymous
TRIAL

a year ago

18.18.0


a year ago

you do use pnpm locally right


Anonymous
TRIAL

a year ago

yes


Anonymous
TRIAL

a year ago

you think I'm installing mac-scpecific stuff?


a year ago

there are no errors duing the install phase


a year ago

can you run pnpm build locally without issues?


Anonymous
TRIAL

a year ago

no, there are not


Anonymous
TRIAL

a year ago

Yes, I do it like 5 times a day because it's convenient


a year ago

are you making sure node_modules and the built files arent making it into your repo


Anonymous
TRIAL

a year ago

Wait, let me test something locally


Anonymous
TRIAL

a year ago

Yes, both configs build locally fine

1214664304465285151


Anonymous
TRIAL

a year ago

Yes, they are all gitignored (shaded/dark files are gitignored)

1214664580748284000


a year ago

you ran a different build command than what you are telling railway to run


Anonymous
TRIAL

a year ago

I tested both locally


Anonymous
TRIAL

a year ago

Gonna try pnpm build -f astro.node.config.ts on railway


Anonymous
TRIAL

a year ago

Same error


a year ago

this error wouldnt be isolated to railway, have you tried searching for solutions to the error?


Anonymous
TRIAL

a year ago

Is the bookmark the only way to download the logs?


Anonymous
TRIAL

a year ago

Gonna give build a try in a lxc container


a year ago

unless you want to use railway's api directly, yes


Anonymous
TRIAL

a year ago

Then in my vps


Anonymous
TRIAL

a year ago

I isolated the problem to be an issue with Astro hybrid mode. For some reason, when running on hybrid mode is not following the normal flow for pages that are not found, and crashes. Using server mode doesn't suffer from that problem