Deploying Astro on Railway

nilansahaHOBBY

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

a year ago

what is your start script?


nilansahaHOBBY

a year ago

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


a year ago

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


nilansahaHOBBY

a year ago

Just the usual

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


a year ago

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


a year ago

send me your astro.config.mjs please


nilansahaHOBBY

a year 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"
  })
});

a year ago

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


a year ago

what vin said, plus you will need -

server: {
  host: '0.0.0.0'
},

in defineConfig


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

a year ago

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


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

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

a year ago

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


nilansahaHOBBY

a year ago

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


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

a year ago

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


a year ago

correct


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

a year ago

Gotcha gotcha. Appreciate the help guys.


a year ago

no problem!


Deploying Astro on Railway - Railway Help Station