Deploying a Static Astro Site on Railway
Astro is a framework for building websites. Railway is a platform for hosting web apps. This guide shows you how you can host an Astro website on Railway.
Prerequisites
- GitHub Account
- Railway Account
- Node.js
Create Astro app
On your local machine, create a new folder named 'my-app'.
mkdir my-app Open my-app.
cd my-app Create a package.json file and add the following:
{ "scripts": { "dev": "astro dev", "start": "astro dev", "build": "astro build", "preview": "astro preview" }, "dependencies": { "astro": "^4.16.5" } } Install the dependencies.
npm install Create a src/pages folder and add a src/pages/index.astro file.
mkdir -p src/pages && touch src/pages/index.astro Add this to src/pages/index.astro
<h1>Hello, World!</h1> Run the development server.
npm run dev Visit http://localhost:4321 to view your site.
lynx localhost:4321 Build Site
Stop your server and build your Astro site:
npm run build Astro will produce a dist folder containing the static site you will deploy.
Preview your build:
npm run preview Deploy to Railway
Install the Railway CLI tool:
npm i -g @railway/cli Login to your Railway account:
railway login --browserless Create a new Railway project:
railway init Link the dist folder to your Railway project.
Change working directory to dist.
cd dist Link current directory, i.e. dist to your Railway project.
railway link Deploy your app.
railway up --detach When site is ready, generate a domain.
railway domain Test Deployment
lynx <YOUR-APP-DOMAIN> Update Site and Redeploy
Update home page, src/pages/index.astro:
<h1>Hello World!</h1> <p>Happy to be here</p> Test update locally:
npm run dev Rebuild site:
npm run build Redeploy to Railway.
cd dist && railway up --detach
Top comments (0)