web/versioned_docs/version-0.22/deployment/deployment-methods/wasp-deploy/railway.md
import { Required } from '@site/src/components/Tag'; import LaunchCommandEnvVars from './_launch-command-env-vars.md' import CustomPostgresOption from './_railway-custom-postgres-option.md' import CiCdMention from './_ci-cd-mention.md' import CustomServerUrlOption from './_custom-server-url-option.md'
Railway is a cloud development platform that streamlines building and deploying applications with built-in support for databases and services. It offers an intuitive interface and automates infrastructure.
To deploy to Railway using Wasp CLI:
Create a Railway account,
Install the railway CLI on your machine.
Using the Wasp CLI, you can easily deploy a new app to Railway with a single command:
wasp deploy railway launch my-wasp-app
Keep in mind that:
Your project name (for example my-wasp-app) must be unique across all your Railway projects or deployment will fail (this is a current limitation of the Wasp CLI and Railway integration #2926).
If you are a member of multiple Railway organizations, the CLI will prompt you to select the organization under which you want to deploy your app.
The project name is used as a base for your server and client service names on Railway:
my-wasp-app-clientmy-wasp-app-serverRailway doesn't allow setting the database service name using the Railway CLI. It will always be named Postgres. This also applies when using the --db-image flag.
If you have any additional environment variables that your app needs, read how to set them in the API Reference section.
<CiCdMention />Setting up a custom domain is a three-step process:
Add your domain to the Railway client service:
my-wasp-app).my-wasp-app-client).mycoolapp.com) and port 8080.Update the DNS records for your domain, adding a CNAME record at the domain or subdomain you want, pointing to the address you've been given in the previous step. This step depends on your domain provider, consult their documentation in case of doubt.
To avoid CORS errors, you need to set your new client URL as the WASP_WEB_CLIENT_URL environment variable (for example https://mycoolapp.com) for your server service in the Railway dashboard.
my-wasp-app).my-wasp-app-server).Update the WASP_WEB_CLIENT_URL variable with the new domain for your client.
That's it, your app should be available at https://mycoolapp.com!
launch commandlaunch is a convenience command that runs setup and deploy in sequence.
wasp deploy railway launch <project-name>
It accepts the following arguments:
<project-name> <Required />
The name of your project.
Running wasp deploy railway launch is the same as running the following commands:
wasp deploy railway setup <project-name>
wasp deploy railway deploy <project-name>
By default, Wasp CLI tries to create a new Railway project named <project-name>. If you want to use an existing Railway project, pass its ID with --existing-project-id option:
wasp deploy railway launch <project-name> --existing-project-id <railway-project-id>
By default, Wasp CLI will prompt you to select a Railway workspace for your project. If you want to skip the prompt and provide the workspace id or name directly, use the --workspace option:
wasp deploy railway launch <project-name> --workspace <railway-workspace-id-or-name>
If you are deploying an app that requires any other environment variables (like social auth secrets), you can set them with the --server-secret option:
wasp deploy railway launch my-wasp-app --server-secret GOOGLE_CLIENT_ID=<...> --server-secret GOOGLE_CLIENT_SECRET=<...>
If you've added any client-side environment variables to your app, pass them to the terminal session before running the launch command, for example:
REACT_APP_ANOTHER_VAR=somevalue wasp deploy railway launch my-wasp-app
deploy commandThe deploy command deploys your client and server apps to Railway.
wasp deploy railway deploy <project-name>
It accepts the following arguments:
<project-name> <Required />
The name of your project.
Run this command whenever you want to update your deployed app with the latest changes:
wasp deploy railway deploy <project-name>
When you run the deploy command, Wasp CLI will use the Railway project that's linked to the Wasp project directory. If no Railway project is linked, the command will fail asking you to run the setup command first.
If you are deploying your Railway app in the CI, you can pass the --existing-project-id option to tell Wasp CLI the Railway project ID to use for the deployment:
wasp deploy railway deploy <project-name> --existing-project-id <railway-project-id>
--skip-client - do not deploy the web client--skip-server - do not deploy the serverIf you've added any client-side environment variables to your app, pass them to the terminal session before running the deploy command, for example:
REACT_APP_ANOTHER_VAR=somevalue wasp deploy railway deploy <project-name>
You must specify your client-side environment variables every time you redeploy with the above command to ensure they are included in the build process.
<CustomServerUrlOption provider="railway" command="deploy" example="my-wasp-app" />setup commandThe setup command creates your client, server, and database services on Railway. It also configures environment variables. It does not deploy the client or server services.
wasp deploy railway setup <project-name>
It accepts the following arguments:
<project-name>
the name of your project.
The project name is used as a base for your server and client service names on Railway:
<project-name>-client<project-name>-serverRailway also creates a PostgreSQL database service named Postgres.
By default, Wasp CLI tries to create a new Railway project named <project-name>. If you want to use an existing Railway project, pass its ID with --existing-project-id option:
wasp deploy railway setup <project-name> --existing-project-id <railway-project-id>
By default, Wasp CLI will prompt you to select in which Railway workspace you want to create your project. If you want to skip the prompt and provide the workspace id or name directly, use the --workspace option:
wasp deploy railway setup <project-name> --workspace <railway-workspace-id-or-name>
:::caution Execute Only Once
You should only run setup once per app. Wasp CLI skips creating the services if they already exist.
:::
If your app requires any other server-side environment variables (like social auth secrets), you can set them:
launch or setup commands with the --server-secret optionIf you've added any client-side environment variables to your app, pass them to the terminal session before running a deployment command, for example:
REACT_APP_ANOTHER_VAR=somevalue wasp deploy railway launch my-wasp-app
or
REACT_APP_ANOTHER_VAR=somevalue wasp deploy railway deploy
Please note that you should do this for every deployment, not just the first time you set up the variables. One way to make sure you don't forget to add them is to create a deploy script in your package.json file:
{
"scripts": {
"deploy": "REACT_APP_ANOTHER_VAR=somevalue wasp deploy railway deploy"
}
}
Then you can run npm run deploy to deploy your app.