In this blog, I teach you how to write python in github repo to establish a http server.
- Your main file: app.py should have this code:
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
- 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.