Deploying Astro on Railway
I am trying to deploy an Astro project on Railway and its not working. I have the PORT env variable set to 4321 and I am using the Node adapter. However when I visit the link generated by Railway it shows me this.
Would appreciate any help.
19 Replies
Project ID:
N/A
what is your start script?
I do not have one. Isn't Railway supposed to auto detect and take care of it?
in your package.json, do you not have a start script?
Just the usual
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "astro build",
"preview": "astro preview",
"astro": "astro"
},
then you are trying to run a dev server on railway, you dont need me to tell you thats not a good idea
send me your astro.config.mjs please
Sure.
Start should be
node ./dist/server/entry.mjs
Solution
what vin said, plus you will need -
in
defineConfig
Gotcha. Is this because I am using the Node adapter or either way?
this type of config applies to any web service you deploy to railway, they need to be listening on either
0.0.0.0
or ::
and the PORT
environment variable, this is just the config required to have the node adapter listen on the correct host and portFirst of all appreciate the answer. I was able to make it work. What I meant was if I wasn't using the Node adapter in Astro, would I still need to use
node ./dist/server/entry.mjs
and server: { host: '0.0.0.0' }
Nextjs for example just runs of the bat without any edits on the package.json and stuff
Or would the start command change in Astro without the Node adapterif you weren't using the node adapter you would be running a development server, yes you could configure the development server to work correctly, but its still a development server.
next apps do come with a default start script as
next start
and that alone is sufficient to run a production server for the most part.Makes sense. I guess without the Node adapter there would be no server running in Astro, just a bunch of static files?
correct
there would be a server running, but without the
node ./dist/server/entry.mjs
as your start script you would be running a dev server instead as the original start script is astro dev
Gotcha gotcha. Appreciate the help guys.
no problem!