W
Wasp2mo ago
Kynetix

Deploying to railway

What are the complete steps for deploying to Railway? My Opensaas application has a Git repo, and it uses Supabase as the backend
22 Replies
kapa.ai
kapa.ai2mo ago
Hi @Kynetix. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To deploy your Wasp (Opensaas) application to Railway, here are the complete steps based on the official documentation. Since you are using Supabase as your backend, you can skip the steps related to provisioning a PostgreSQL database on Railway and instead configure your app to use your Supabase database URL. 1. Prerequisites - Make sure your Wasp app is built:
wasp build

wasp build

- Create a Railway account. - Install the Railway CLI. - Authenticate with Railway:
railway login

railway login

2. Create a New Railway Project - Go to your Railway dashboard. - Click New Project. - Since you are using Supabase, you can skip provisioning PostgreSQL on Railway. - Create two empty services: one named server and one named client (instructions here). 3. Setup Domains - In the Railway dashboard, generate domains for both the server and client services. You’ll need these for environment variables later. 4. Deploy the Server 1. Move into your app's build directory:
cd .wasp/build

cd .wasp/build

2. Link your app build to your Railway project:
railway link

railway link

3. In the Railway dashboard, set up the required environment variables for the server service: - DATABASE_URL — use your Supabase database URL. - WASP_WEB_CLIENT_URL — the domain of your client service. - WASP_SERVER_URL — the domain of your server service. - JWT_SECRET — a random string at least 32 characters long. - Any additional variables required by your app (e.g., for social auth). 4. Deploy the server:
railway up

railway up

Select server when prompted with Select Service (detailed steps). 5. Deploy the Client 1. Change into your app's frontend build directory:
cd web-app

cd web-app

2. Create the production build, using the server domain as the REACT_APP_API_URL:
npm install && REACT_APP_API_URL=<url_to_wasp_backend> npm run build

npm install && REACT_APP_API_URL=<url_to_wasp_backend> npm run build

3. Link this frontend directory to your Railway project:
railway link

railway link

4. Set up static hosting: - Copy the build folder to dist:
cp -r build dist

cp -r build dist

- Create a Dockerfile:
FROM pierrezemb/gostatic
CMD [ "-fallback", "index.html" ]
COPY ./dist/ /srv/http/

FROM pierrezemb/gostatic
CMD [ "-fallback", "index.html" ]
COPY ./dist/ /srv/http/

- Create a .dockerignore:
node_modules/

node_modules/

5. Set the PORT environment variable to 8043 under the Variables tab in Railway. 6. Deploy the client:
railway up

railway up

Select client when prompted (full client deployment steps). 6. After Deployment - In your Railway dashboard, you should see your deployed services. - If you need to redeploy after updates, repeat the build and deploy steps for both server and client (updates & redeploying). --- Note:
- You must repeat the client deployment steps each time you run wasp build, as the .wasp/build/web-app directory is regenerated. - If you want to automate the client deployment, you can use the provided shell script in the docs (see deploy_client.sh example). If you need to customize the Docker setup (e.g., for SPA routing with React Router), see the GitHub issue discussion for advanced Dockerfile and nginx configuration tips. --- For more details, refer to the official Wasp documentation:
- Deploying Manually to Railway ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Kynetix, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Kynetix
KynetixOP2mo ago
@kapa.ai since I have the code in github, can Railway be configured to deploy from github whenever the code is updated?
kapa.ai
kapa.ai2mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- The knowledge sources provided do not contain explicit information about configuring Railway to automatically deploy your Wasp app from GitHub whenever the code is updated. The official Wasp documentation and related GitHub issues focus on manual deployment using the Railway CLI and do not mention CI/CD integration or GitHub-based automatic deployments for Wasp apps on Railway. If you need automated deployments from GitHub, you may need to consult Railway's own documentation or explore their GitHub integration features directly, as this is not covered in the Wasp documentation or the sources provided here. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Kynetix, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Carlos
Carlos2mo ago
Hey @Kynetix, we have a tutorial on our docs for deploying to Railway: https://wasp.sh/docs/deployment/deployment-methods/paas#railway
Platform as a Service (PaaS) | Wasp
This document explains how to build and prepare your Wasp app for deployment.
Carlos
Carlos2mo ago
is that useful?
Kynetix
KynetixOP2mo ago
Yes it is, @Carlos . Thanks 🙂 @kapa.ai I've followed the steps and deployed both the client and the server. However, in the Railway dashboard, the client service crashed while deploying. In the "Deploy Logs" tab, under Starting Container and Listening to https://0.0.0.0:8043, it says "level: "error" replica: 5a03ed52-7f05-4bbd-8c53-0e4dec27b9d1", and when I visit the client link, I get the 502: Bad Gateway error. How do I resolve this??
MEE6
MEE62mo ago
Wohooo @Kynetix, you just became a Waspeteer level 6!
kapa.ai
kapa.ai2mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Based on the knowledge sources, a 502: Bad Gateway error and a client service crash on Railway often indicate an issue with the static hosting setup or the Docker configuration for your client deployment. Here are the key things to check and steps to resolve: 1. Correct Dockerfile and .dockerignore
Ensure you have created the correct Dockerfile and .dockerignore in your .wasp/build/web-app directory before running railway up. The Dockerfile should look like this:
FROM pierrezemb/gostatic
CMD [ "-fallback", "index.html" ]
COPY ./dist/ /srv/http/

FROM pierrezemb/gostatic
CMD [ "-fallback", "index.html" ]
COPY ./dist/ /srv/http/

And .dockerignore should contain:
node_modules/

node_modules/

See official instructions 2. Build and Copy Steps
After building your client, you must copy the build folder to dist:
cp -r build dist

cp -r build dist

This is required because the Dockerfile expects the static files in dist/ (source). 3. Environment Variable: PORT
In the Railway dashboard, under the client service's Variables tab, set the PORT environment variable to 8043 (source). 4. REACT_APP_API_URL
When building the client, make sure you set the REACT_APP_API_URL to your deployed server's URL:
npm install && REACT_APP_API_URL=<url_to_wasp_backend> npm run build

npm install && REACT_APP_API_URL=<url_to_wasp_backend> npm run build

If this is not set correctly, the client may not function as expected. 5. Repeat Steps After Each Build
Every time you run wasp build, the .wasp/build/web-app directory is regenerated, so you must repeat the Dockerfile, .dockerignore, and dist setup steps before deploying (source). 6. Check Deploy Logs for More Details
If the above steps are correct and the error persists, review the full deploy logs for more specific error messages that could indicate missing files or misconfiguration. If you follow these steps and ensure the static hosting setup is correct, the 502 error should be resolved. If the problem continues, please provide the full error log from the "Deploy Logs" tab for more targeted troubleshooting. For reference, see the official Wasp Railway deployment guide. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Kynetix, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Kynetix
KynetixOP2mo ago
@kapa.ai I've followed the steps and deployed both the client and the server. However, in the Railway dashboard, the client service crashed while deploying. In the "Deploy Logs" tab, under Starting Container and Listening to https://0.0.0.0:8043/, it says "level: "error" replica: 5a03ed52-7f05-4bbd-8c53-0e4dec27b9d1", and when I visit the client link, I get the 502: Bad Gateway error. How do I resolve this??
kapa.ai
kapa.ai2mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- A 502: Bad Gateway error and a client service crash on Railway typically indicate an issue with the static hosting setup or Docker configuration for your client deployment. Here’s what you should check, based strictly on the knowledge sources: 1. Dockerfile and .dockerignore
Make sure you have created a Dockerfile in .wasp/build/web-app with the following content:
FROM pierrezemb/gostatic
CMD [ "-fallback", "index.html" ]
COPY ./dist/ /srv/http/

FROM pierrezemb/gostatic
CMD [ "-fallback", "index.html" ]
COPY ./dist/ /srv/http/

And a .dockerignore file with:
node_modules/

node_modules/

See: Deploying the Client 2. Copy Build to Dist
After building your client, copy the build folder to dist:
cp -r build dist

cp -r build dist

This is required because the Dockerfile expects the static files in dist/ (source). 3. Set the PORT Environment Variable
In the Railway dashboard, under the client service’s Variables tab, set the PORT environment variable to 8043 (source). 4. Repeat After Each Build
Every time you run wasp build, the .wasp/build/web-app directory is regenerated, so you must repeat the Dockerfile, .dockerignore, and dist setup steps before deploying (source). If you have already done all of the above and the error persists, please check the full deploy logs for more specific error messages, as the knowledge sources do not provide further troubleshooting steps for this specific error. If you need to automate these steps, the docs provide a shell script example to help ensure the process is followed correctly each time (see deploy_client.sh). If you continue to experience issues, please provide the full error log from the "Deploy Logs" tab for more targeted help. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Kynetix, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Carlos
Carlos2mo ago
@miho has been working with Railway lately, have you seen this error?
miho
miho2mo ago
Are those full client logs? Do you see anything else? Have you followed the "Setting Up Static Hosting" section of the Railway deployment in the docs?
miho
miho2mo ago
No description
Kynetix
KynetixOP2mo ago
Hi @miho that's the entire error, nothing else (see attachment). I did the static hosting step too
No description
Kynetix
KynetixOP2mo ago
No description
Kynetix
KynetixOP2mo ago
Meanwhile I decided to give fly.io a shot, but I'm stuck on setting up WASP_WEB_CLIENT_URL and WASP_SERVER_URL. Where do I get those from?
miho
miho2mo ago
I'd advise reading the general deployment docs to get the idea about what's needed 🙂 https://wasp.sh/docs/deployment/env-vars In short, you need the URLs from Fly which are generated based on your app name e.g. my-app.fly.dev or smth like that
Env Variables | Wasp
We talked about environment variables in the project setup section. If you haven't read it, make sure to check it out first. In this section, we'll talk about environment variables in the context of deploying the app.
miho
miho2mo ago
For Fly, you can try using our one-line command deployment: https://wasp.sh/docs/deployment/deployment-methods/cli
Wasp CLI | Wasp
Wasp CLI can deploy your full-stack application with only a single command.
miho
miho2mo ago
This is wild! It looks like some weird Railway error to me 😄 You try adding an empty Staticfile file instead of Dockerfile. This will trigger Railway to use their static site Buildpack - it might work for you that way.
Kynetix
KynetixOP2mo ago
Thanks @miho . My app's URL is build-hidden-pond-2826.fly.dev, so I set it as both CLIENT_URL and SERVER_URL, but when I visit the site, I get a 502 error. Maybe I'm missing something?
No description
miho
miho2mo ago
There is the client URL and the server URL (two different apps), you need to include https:// in the value. Check the server logs on Fly to see if you get any errors (maybe some missing env vars).
Kynetix
KynetixOP2mo ago
Thanks, @miho . Carlos refered me to these instructions https://wasp.sh/docs/deployment/deployment-methods/cli#flyio which seem to work now. Thanks again
Wasp CLI | Wasp
Wasp CLI can deploy your full-stack application with only a single command.

Did you find this page helpful?