Skip to content

Instantly share code, notes, and snippets.

@BruceWind
Last active July 26, 2024 11:46
Show Gist options
  • Save BruceWind/ffe82dd41aca2848d33ba8cdff317e39 to your computer and use it in GitHub Desktop.
Save BruceWind/ffe82dd41aca2848d33ba8cdff317e39 to your computer and use it in GitHub Desktop.
teach you how to write python in github repo to establish a http server.

In this blog, I teach you how to write python in github repo to establish a http server.

  1. Your main file: app.py should have this code:
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def root():
    return {"message": "Hello World"}
  1. your railway.json file:
{
  "$schema": "https://railway.app/railway.schema.json",
  "build": {
    "builder": "NIXPACKS"
  },
  "deploy": {
    "startCommand": "uvicorn app:app --host 0.0.0.0 --port \"$PORT\""
  }
}

uvicorn app:app in above means "uvicorn {filename}:{variable name in file}

And you may need a requirements.txt file to help railway to install your dependencies.

After all, you can open railway.app to create a project, and link to the github repo. It will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment