惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
SecWiki News
SecWiki News
WordPress大学
WordPress大学
小众软件
小众软件
博客园 - 司徒正美
酷 壳 – CoolShell
酷 壳 – CoolShell
V
Visual Studio Blog
Y
Y Combinator Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
K
Kaspersky official blog
T
The Exploit Database - CXSecurity.com
腾讯CDC
Scott Helme
Scott Helme
I
InfoQ
Cyberwarzone
Cyberwarzone
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Security Latest
Security Latest
The Register - Security
The Register - Security
Project Zero
Project Zero
F
Fortinet All Blogs
C
CERT Recently Published Vulnerability Notes
A
Arctic Wolf
C
Cisco Blogs
L
LINUX DO - 热门话题
P
Privacy International News Feed
IT之家
IT之家
U
Unit 42
P
Privacy & Cybersecurity Law Blog
H
Help Net Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Palo Alto Networks Blog
F
Full Disclosure
宝玉的分享
宝玉的分享
Simon Willison's Weblog
Simon Willison's Weblog
L
Lohrmann on Cybersecurity
Google DeepMind News
Google DeepMind News
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
H
Hacker News: Front Page
Know Your Adversary
Know Your Adversary
PCI Perspectives
PCI Perspectives
Hugging Face - Blog
Hugging Face - Blog
AWS News Blog
AWS News Blog
MongoDB | Blog
MongoDB | Blog
S
Schneier on Security
Recent Announcements
Recent Announcements
Forbes - Security
Forbes - Security
Cisco Talos Blog
Cisco Talos Blog

Railway Blog

Where Railway is, and where it's going (Summer 2026) PaaS vs IaaS vs SaaS: What Each Means and Who Should Pick What in 2026 The Best Continuous Deployment Tools in 2026 The Best PaaS for Multi-Region Deployments in 2026 The Best Platforms for Monorepo Deployments in 2026 Compliance Isn't a Feature, It's a Posture What is BYOC (Bring Your Own Cloud)? A Developer's Guide for 2026 The Best Managed Kubernetes Hosting in 2026 The Best Container Registries in 2026 The Vanilla Cloud Tax: What Rolling Your Own on AWS Actually Costs What is a PaaS? A Developer's Guide for 2026 The Best Cloud Observability and Logging Tools in 2026 The Best PostgreSQL Hosting for Developers in 2026 The Best Multi-Region Hosting Platforms in 2026 The Best Platforms to Deploy AI Apps in 2026 (Not the Models, the Apps Around Them) The Agent-Native Cloud: What It Means and Why It Matters Incident Report: May 19, 2026- GCP Account Suspension Counting to 3 with a new builder processing 50M+ monthly builds Railway iOS preview now available via TestFlight Kill your onboarding: selling to 10,000+ new users a day Your AI wants to nuke your database. Guardrails fix that. Better Rails for Agents: A New Remote MCP and Railway Agent in the CLI Moving Railway's Frontend Off Next.js One command deploys, there's a Stripe APP for that From registrar to deployed: buying a domain inside Railway A letter to open source builders who deserve more Networking is a black box, we used eBPF to open it Heroku Walked So Railway Can Run Security Features Your Security Team Will Love Railway Runs Open Source, Now We're Funding It Railway raises $100M Series B to unburden the builders Deploy autoscaling services, AI Workflow automation, and LLM APIs Without Kubernetes Hosting Postgres with GeoLite2: a practical guide to IP geolocation, data loading, and updates Serverless functions vs containers: CI/CD, database connections, cron jobs, and long-running tasks Hosting Postgres with pgvector: provider tradeoffs, migrations, indexes, and tuning Introducing the Railway integration on Delve.co Secure Cloud Hosting for Compliance: A Practical Guide for Startups and Regulated Industries How G2X Unlocked Rapid Experimentation at Scale with Railway MindFort Runs 100+ AI Pen Testing Agents Without Their Previous $10k AWS Bill How Bilt's Marketing Engineering Team Delivers at Scale with Railway Railway Technology Partners: Earn Revenue on Templates You Didn't Build ~$1 Million Paid to Developers Who Built Railway Templates CI/CD for Modern Deployment: From Manual Deploys to PR Environments Kernel Powers 1,000+ AI Agents on $444/Month of Railway Infrastructure Deploy Full-Stack TypeScript Apps: Architectures, Execution Models, and Deployment Choices Railway vs Cloudflare: How Their Architectures Differ and When to Use Each Run Scheduled and Recurring Tasks with Cron Monitoring & Observability: Using Logs, Metrics, Traces, and Alerts to Understand System Failures Logs, Metrics, and Traces: What Does Each Signal Tell You? Server rendering benchmarks: Railway vs Cloudflare vs Vercel Top five Heroku alternatives Comparing top PaaS and deployment providers Pricing to Encourage Use The F in SOC2 stands for functional Deploy Together, Earn Together: Introducing Railway Partnerships How We Oops-Proofed Infrastructure Deletion on Railway Bring Back the Free Plan Railway MCP - Stateful, Serverful, Pay-per-use Infrastructure Hackathon: Winners Announced! Mark Your Calendar: Railway User Hackathon with Prizes Launching Railway's Affiliate Program Zero-Touch Bare Metal at Scale Ssh, We’re Announcing One More Thing! $1M for Open Source Introducing Central Station Speed Isn’t Just About Code, It’s About Where That Code Runs One-Second Deploys? We Didn’t Believe It Either Why We’re Moving on From Nix Railway V3: Faster and Cheaper How to Migrate from Cloudflare Pages to Railway Supercharging Directus on Railway with a Static Frontend How to Migrate from AWS Lambda to Railway Deploy Triton Inference Server on Railway How to Handle Database Connection Pooling Building a NestJS App on Railway Manually Optimize Deployments on Railway Implement a GitHub Actions Testing Suite Scaling a SaaS application on Railway Building a SaaS application on Railway Deploy a Dart App on Railway, Part 2 Implementing Feature Flags from Scratch Cron Jobs with Django and GitHub Actions Deploy Offen on Railway Queues on Railway Working with NX, Railway and CI/CD Automated PostgreSQL Backups Using GitLab CI/CD with Railway Migrating From Heroku To Railway Cron Jobs on Railway Deploy Beam on Railway Deploy Authorizer on Railway Deploying Monorepo Applications How to Backup and Restore Your Postgres Database How to Backup Your Redis Instance Deploy Cusdis on Railway Deploy Ghost on Railway Using Github Actions with Railway Deploy Calendso (cal.com) on Railway Self-hosted website analytics Use Notion as a CMS for your NextJS blog
Deploy a Dart App on Railway, Part 1
Andrew Bekhiet · 2024-12-13 · via Railway Blog

Avatar of Andrew Bekhiet

Andrew Bekhiet

Have you ever been on a trip with friends and found yourself in a heated trivia competition?

No ….? Ok … no problem

However, if your answer was yes, then the rest is for you!

That's what happened to me recently. While waiting to reach our destination, me and my friends started a "who knows best" game. It was fun and exciting, but I quickly realized there was room for improvement.

The problem? No one was keeping track of the score, and we kept arguing over the correct answers.

As such, and as a programmer, I decided to make an app

Pro-gamer move
Pro-gamer move

The End Goal 🏆

The goal is simple, to make an app that everyone can use to play trivia games.

  • All players see the same question at the same time and everyone has a chance to answer.
  • After all players submit their answers, the app will show the correct answer on the host device, whether or not each player answered correctly on their devices.
  • A bonus is added to players who answer quicker than others.
  • After all questions are answered by all players, the final result is shown on the host, and the rank of each player is shown on their device.
  • Players can sign up for an account to be able to create games and host them
Overview of app flow
Overview of app flow

Tech stack 🛠️

Frontend

For this tutorial, we’ll be using Flutter for the frontend with rxdart streams for realtime communications and Riverpod for dependency injection.

Backend

And for the backend, I didn’t really know which Dart package/framework to choose. So I did a small research and decided to go with Serverpod. Why? glad you asked:

  • Typesafe Dart: Serverpod allows you to call functions from your Flutter app as if they were in another file, it doesn’t feel like you’re calling some flaky string function name with flaky json, it’s all typesafe Dart from client to server
  • Better Developer Experience: Serverpod offers many features that makes backend development very efficient. Things like automatic code generation, built-in ORM, migrations and logging

In addition, it has built in support for authentication and data streaming, which we need in this project to build realtime multiplayer experience

Initial project setup 📁

So, and without further ado, let’s get started and create a new Flutter + Serverpod project

Serverpod CLI

  • First off, download the Serverpod CLI
dart pub global activate serverpod_cli

New Serverpod project

  • Create a new Serverpod project and open it in your preferred code editor
serverpod create trivyal
cd trivyal

Project structure

If this is your first time using Serverpod, check out their documentation to understand Serverpod project structure

Railway setup 🚄

Let’s get our project setup in Railway!

Adding a database

  • Head to dev.new to create a new project on Railway
  • Select Deploy PostgreSQL from the options
Selecting PostgresQL from New Project prompt
Selecting PostgresQL from New Project prompt
  • After the database is deployed, you can go to settings and enable App Sleeping so our elephant doesn’t get sleep deprived

Running first database migration

  • Edit the trivyal_server/config/production.yaml file to match the deployed railway db
  • In the settings tab under Networking, copy the provided TCP proxy host and port number
  • Update the values in trivyal_server/config/production.yaml

The provided host should end with .proxy.rlwy.net

Here the public networking proxy hostname is autorack.proxy.rlwy.net and the provided port is 46821
Here the public networking proxy hostname is autorack.proxy.rlwy.net and the provided port is 46821

This is how your database section should look like in production.yaml:

database:
  host: postgres.railway.internal # Or railway proxy provided hostname (something.proxy.rlwy.net)
  port: 46821
  name: railway
  user: postgres
  requireSsl: true
  • Go to trivyal_server/config/passwords.yaml file and change the database password to match the deployed database password

⚠️

Warning: Never commit your plain text passwords to git

  • Now that serverpod has all the info to connect to our database, we’re ready to run the first migration using:
dart bin/main.dart --mode production --apply-migrations

Make sure to run the previous command in the trivyal_server directory

Railway Up

  • Install the Railway CLI using your preferred method, for example using Homebrew:
brew install railway
  • Authenticate your CLI session:
railway login
  • Link to the project and service:
railway link
  • Finally, use Railway up to deploy the code:
railway up -d

Railway will automatically detect the Dockerfile at the root of the project and automatically build and deploy our app

Adding flutter web build

The provided Dockerfile at trivyal_server/Dockerfile only builds the server directory, but doesn’t add the flutter web build to the static hosting

To fix this:

  • Move the trivyal_server/Dockerfile to the root of our monorepo
  • Edit Dockerfile so it installs Flutter SDK, makes a web build and copies the build to our trivyal_server/web directory
FROM dart:stable AS build

WORKDIR /server
COPY trivyal_server .

# Build our server
RUN dart pub get
RUN dart compile exe bin/main.dart -o bin/server

WORKDIR /web
COPY trivyal_flutter/ .
# Copy our client package code. The flutter app depends on it
COPY trivyal_client/ ../trivyal_client/

# Install Flutter SDK
RUN apt-get update && apt-get -y install curl git unzip xz-utils zip libglu1-mesa
RUN git clone https://github.com/flutter/flutter.git /usr/local/flutter
ENV PATH="${PATH}:/usr/local/flutter/bin"

# Run web build
RUN flutter pub get
RUN flutter build web

FROM alpine:latest

ENV runmode=production
ENV serverid=default
ENV logging=normal
ENV role=monolith

# Copy dart runtime and build artifacts
COPY --from=build /runtime/ /
COPY --from=build /server/bin/server server
COPY --from=build /server/config/ config/
COPY --from=build /server/web/ web/
COPY --from=build /server/migrations/ migrations/

COPY --from=build /web/build/web/ web/

EXPOSE 8080
EXPOSE 8081
EXPOSE 8082

ENTRYPOINT ./server --mode=$runmode --server-id=$serverid --logging=$logging --role=$role

If you named your project differently, you should update the directories’ names in the previous Dockerfile

  • Remove the default Serverpod index template in trivyal_server/web and its renderer in trivyal_server/lib/src/web
  • Update trivyal_server/lib/server.dart file:
import 'package:serverpod/serverpod.dart';

import 'package:trivyal_server/src/web/routes/root.dart';

import 'src/generated/protocol.dart';
import 'src/generated/endpoints.dart';

// This is the starting point of your Serverpod server. In most cases, you will
// only need to make additions to this file if you add future calls,  are
// configuring Relic (Serverpod's web-server), or need custom setup work.

void run(List<String> args) async {
  // Initialize Serverpod and connect it with your generated code.
  final pod = Serverpod(
    args,
    Protocol(),
    Endpoints(),
  );

  // If you are using any future calls, they need to be registered here.
  // pod.registerFutureCall(ExampleFutureCall(), 'exampleFutureCall');

  // Serve all files in the trivyal_server/web directory.
  // This directory will be populated by Docker with our flutter web build.
  pod.webServer.addRoute(
    RouteStaticDirectory(
      serverDirectory: '.',
      serveAsRootPath: '/index.html',
      basePath: '/',
    ),
    '/*',
  );

  // Start the server.
  await pod.start();
}

Deploying the server

  • Go back to Railway dashboard and press (Ctrl+K or Command+K) to open the Railway command palette
  • Choose to deploy a new empty service
Choosing new empty service
Choosing new empty service

Environment Variables

To make our server able to connect to our postgres database, we need to setup environment variables. Don’t worry no need to go back and forth between both services, as Railway provides variables references that allow us to reference variables from our postgres service to our server

  • Go to Variables tab and paste this JSON in the Raw editor:
{
  "SERVERPOD_DATABASE_USER": "${{Postgres.POSTGRES_USER}}",
  "SERVERPOD_DATABASE_PASSWORD": "${{Postgres.POSTGRES_PASSWORD}}",
  "SERVERPOD_DATABASE_HOST": "${{Postgres.RAILWAY_PRIVATE_DOMAIN}}",
  "SERVERPOD_DATABASE_PORT": "5432",
  "SERVERPOD_DATABASE_NAME": "${{Postgres.POSTGRES_DB}}",
  "SERVERPOD_DATABASE_REQUIRE_SSL": "true"
}
  • Also, go to service settings and enable App Sleeping so our server can sleep at network traffic nights
  • Finally, click Deploy changes or press Shift+Enter

Railway will detect the Dockerfile at the root of the project and automatically build and deploy our app.

Caddy reverse proxy

Because Serverpod is modular and you may not need to use all the features at once, by default the api server listens on port 8080 and the webserver listens on 8082

Since we can use Railway’s provided domain for only one port (for now), we would need to split the http traffic somehow to port 8080 and port 8082 for the api and the static webserver respectively

Luckily, we can use this ready-to-delpoy Serverpod reverse proxy template

  • Press Ctrl+K or Command+K and choose to deploy a new service from a template
  • From the templates list, choose Serverpod reverse proxy: Unite your frontend & serverpod backend under one domain
Selecting the Serverpod reverse proxy
Selecting the Serverpod reverse proxy
  • If you kept all Serverpod’s default config, the api server should be at port 8080 and the webserver at port 8082. The domain should be the Serverpod service private domain So your Caddy service environment variables should look like this:
{
  "BACKEND_PORT": "8080",
  "FRONTEND_PORT": "8082"
  "BACKEND_DOMAIN": "${{trivyal.RAILWAY_PRIVATE_DOMAIN}}",
  "FRONTEND_DOMAIN": "${{trivyal.RAILWAY_PRIVATE_DOMAIN}}",
}

Change the domain

  • After the reverse proxy is deployed, go to Networking section and change the domain name to anything you like
How your canvas should look like at the end of Railway backend setup
How your canvas should look like at the end of Railway backend setup

The moment of truth

To make sure everything is working, go to your caddy proxy’s domain. You should see something like this:

Testing that your Serverpod service is working
Testing that your Serverpod service is working

And if you make a get request to /api/example/hello?name=world, it should return “Hello world”

$ curl "https://trivyal.up.railway.app/api/example/hello?name=world"
"Hello world"%

If that is not the case, you might need to check the server logs in Railway

Anyways, that was just part 1 of Deploying a Dart app to Railway, if you want to continue reading, you should checkout part 2

Useful Resources 📖

Here are some helpful resources if you have any trouble.