R
Railway15mo ago
xbisa

Angular SSR

I'm planning to deploy an angular app with server side rendering. Does Railway support it? At the moment the rendering is in the browser. I have build and start scripts in my package json that looks like this "build": "ng build --configuration $NODE_ENV", "start": "serve dist/app-name -s -n -L -p $PORT", but with server side rendering it's a bit different "serve:ssr": "node dist/app-name/server/main.js", According to Angular docs: Starts the server script for serving the application locally with server-side rendering. It uses the build artifacts created by npm run build:ssr, so make sure you have run that command as well. serve:ssr is not intended to be used to serve your application in production, but only for testing the server-side rendered application locally. "build:ssr": "ng build && ng run app-name:server", According to Angular docs: Builds both the server script and the application in production mode. Use this command when you want to build the project for deployment. i have different environments on Railway and I want to build for them, so I can modify "build:ssr": "ng build && ng run app-name:server" to "build:ssr": "ng build --configuration $NODE_ENV && ng run app-name:server". And perhaps I can substitute "build": "ng build --configuration $NODE_ENV" with "build": "ng build --configuration $NODE_ENV && ng run app-name:server". But I'm a little bit doubtful about how I should modify the start script. Could this work: "start": "node dist/app-name/server/main.js -s -n -L -p $PORT" ?
9 Replies
Percy
Percy15mo ago
Project ID: dcc778ee-bff3-412f-bc0c-450c139c5224
xbisa
xbisa15mo ago
dcc778ee-bff3-412f-bc0c-450c139c5224 Update: I have tested the above setup and successfully deployed to my test environment
Brody
Brody15mo ago
the -s -n -L -p flags are specific to the serve package and are not universal
xbisa
xbisa15mo ago
Can I omit them then?
Brody
Brody15mo ago
well yes they don't pertain to angulars built server but angulars built server will still need to listen on 0.0.0.0 and $PORT
xbisa
xbisa15mo ago
It actually does and defaults to 4000 const port = process.env['PORT'] || 4000;
Brody
Brody15mo ago
perfect
xbisa
xbisa15mo ago
thanks again
Brody
Brody15mo ago
no problem
Want results from more Discord servers?
Add your server