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.
No description
Solution:
what vin said, plus you will need - ```js server: { host: '0.0.0.0' },...
Jump to solution
19 Replies
Percy
Percy5mo ago
Project ID: N/A
Brody
Brody5mo ago
what is your start script?
tensor8045
tensor8045OP5mo ago
I do not have one. Isn't Railway supposed to auto detect and take care of it?
Brody
Brody5mo ago
in your package.json, do you not have a start script?
tensor8045
tensor8045OP5mo ago
Just the usual "scripts": { "dev": "astro dev", "start": "astro dev", "build": "astro build", "preview": "astro preview", "astro": "astro" },
Brody
Brody5mo ago
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
tensor8045
tensor8045OP5mo ago
Sure.
import { defineConfig } from "astro/config";
import tailwind from "@astrojs/tailwind";

import node from "@astrojs/node";

// https://astro.build/config
export default defineConfig({
output: "server",
integrations: [tailwind()],
adapter: node({
mode: "standalone"
})
});
import { defineConfig } from "astro/config";
import tailwind from "@astrojs/tailwind";

import node from "@astrojs/node";

// https://astro.build/config
export default defineConfig({
output: "server",
integrations: [tailwind()],
adapter: node({
mode: "standalone"
})
});
MantisInABox
MantisInABox5mo ago
Start should be node ./dist/server/entry.mjs
Solution
Brody
Brody5mo ago
what vin said, plus you will need -
server: {
host: '0.0.0.0'
},
server: {
host: '0.0.0.0'
},
in defineConfig
MantisInABox
MantisInABox5mo ago
import { defineConfig } from 'astro/config';
import node from "@astrojs/node";

import tailwind from "@astrojs/tailwind";

// https://astro.build/config
export default defineConfig({
output: "server",
adapter: node({
mode: "standalone"
}),
server: {
host: '0.0.0.0'
},
integrations: [tailwind({
applyBaseStyles: false,
})]
});
import { defineConfig } from 'astro/config';
import node from "@astrojs/node";

import tailwind from "@astrojs/tailwind";

// https://astro.build/config
export default defineConfig({
output: "server",
adapter: node({
mode: "standalone"
}),
server: {
host: '0.0.0.0'
},
integrations: [tailwind({
applyBaseStyles: false,
})]
});
tensor8045
tensor8045OP5mo ago
Gotcha. Is this because I am using the Node adapter or either way?
Brody
Brody5mo ago
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 port
tensor8045
tensor8045OP5mo ago
First 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 adapter
Brody
Brody5mo ago
if 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.
tensor8045
tensor8045OP5mo ago
Makes sense. I guess without the Node adapter there would be no server running in Astro, just a bunch of static files?
MantisInABox
MantisInABox5mo ago
correct
Brody
Brody5mo ago
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
tensor8045
tensor8045OP5mo ago
Gotcha gotcha. Appreciate the help guys.
Brody
Brody5mo ago
no problem!
Want results from more Discord servers?
Add your server