Deploying Astro on Railway

nilansahaHOBBY

10 months ago

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.

0 Replies

10 months ago

what is your start script?


nilansahaHOBBY

10 months ago

I do not have one. Isn't Railway supposed to auto detect and take care of it?


10 months ago

in your package.json, do you not have a start script?


nilansahaHOBBY

10 months ago

Just the usual

"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "astro build",
"preview": "astro preview",
"astro": "astro"
},


10 months ago

then you are trying to run a dev server on railway, you dont need me to tell you thats not a good idea


10 months ago

send me your astro.config.mjs please


nilansahaHOBBY

10 months 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"
  })
});

10 months ago

Start should be node ./dist/server/entry.mjs


10 months ago

what vin said, plus you will need -

server: {
  host: '0.0.0.0'
},

in defineConfig


10 months 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,
  })]
});

nilansahaHOBBY

10 months ago

Gotcha. Is this because I am using the Node adapter or either way?


10 months 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


nilansahaHOBBY

10 months 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' }


nilansahaHOBBY

10 months ago

Nextjs for example just runs of the bat without any edits on the package.json and stuff


nilansahaHOBBY

10 months ago

Or would the start command change in Astro without the Node adapter


10 months 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.


nilansahaHOBBY

10 months ago

Makes sense. I guess without the Node adapter there would be no server running in Astro, just a bunch of static files?


10 months ago

correct


10 months 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


nilansahaHOBBY

10 months ago

Gotcha gotcha. Appreciate the help guys.


10 months ago

no problem!


Deploying Astro on Railway - Railway Help Station