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
Percy2w ago
Project ID: N/A
Brody
Brody2w ago
what is your start script?
tensor8045
tensor80452w ago
I do not have one. Isn't Railway supposed to auto detect and take care of it?
Brody
Brody2w ago
in your package.json, do you not have a start script?
tensor8045
tensor80452w ago
Just the usual "scripts": { "dev": "astro dev", "start": "astro dev", "build": "astro build", "preview": "astro preview", "astro": "astro" },
Brody
Brody2w 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
tensor80452w 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
MantisInABox2w ago
Start should be node ./dist/server/entry.mjs
Solution
Brody
Brody2w ago
what vin said, plus you will need -
server: {
host: '0.0.0.0'
},
server: {
host: '0.0.0.0'
},
in defineConfig
MantisInABox
MantisInABox2w 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
tensor80452w ago
Gotcha. Is this because I am using the Node adapter or either way?
Brody
Brody2w 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
tensor80452w 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
Brody2w 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
tensor80452w ago
Makes sense. I guess without the Node adapter there would be no server running in Astro, just a bunch of static files?
MantisInABox
MantisInABox2w ago
correct
Brody
Brody2w 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
tensor80452w ago
Gotcha gotcha. Appreciate the help guys.
Brody
Brody2w ago
no problem!