lodebit
ProductBotsDocsPricing soon
Log inDeploy

Adding an API to a site

FastAPI (Python 3.13) · Node.js 24

A site can come with a small backend. Put it in a folder called api at the top of your site, and it answers under /api on the site's address and its own domains. Everything else is still served as static files.

FastAPI

my-site/
  index.html
  api/
    main.py
    requirements.txt

api/main.py must define app. Requests reach it with the path unchanged, so routes start with /api:

from fastapi import FastAPI

app = FastAPI()

@app.get("/api/hello")
def hello(name: str = "world"):
    return {"message": f"Hello, {name}!"}

api/requirements.txt lists your packages and must include uvicorn, which runs the app:

fastapi
uvicorn

Your page can then call it with fetch("/api/hello?name=Sam"). Same address, so there's no CORS to set up.

Node.js

Instead of main.py, add api/package.json with a start script. The server must listen on the port in the PORT environment variable and handle paths that start with /api.

Keys and passwords

Never put keys in your files: .env files inside api/ are removed on deploy. Add them on the site's API page instead. They're encrypted in your browser and given to the backend as environment variables.

How it runs

  • Dependencies are installed fresh on every deploy, and the code and packages are checked like any upload.
  • The backend sleeps after 10 minutes without requests. The next request wakes it, which takes a few seconds, so make startup quick.
  • A new deploy replaces the backend. Rolling back restores the backend of that deploy.
  • Pull request previews and per-deploy addresses serve the static files only. /api runs on the production address.
  • Anything the backend prints shows up live on the site's API page.

Limits

Backends per accountOne per site, and they share the account's 3 slots with bots.
Memory256 MB
CPUHalf a core
RequestsAbout 20 a second per site (bursts up to 40), 30 seconds each, bodies up to 10 MB
FilesThe code is read-only. Write lasting files to /data (also in LODEBIT_DATA_DIR): 100 MB, kept while the backend sleeps and across deploys. Over the limit it turns read-only until you reset it on the site's API page. It isn't backed up yet. /tmp (64 MB) is emptied whenever the backend sleeps.
Not supportedWebSockets, background jobs that outlive a request, and scheduled tasks

Troubleshooting

  • The deploy failed with a message about api/. It says exactly which file is missing. The usual one is uvicorn in requirements.txt.
  • /api answers 502. The backend crashed or didn't start listening in time. The site's API page shows its output.
  • /api answers 404 from FastAPI. The route needs the /api prefix, for example @app.get("/api/hello").
lodebit

Running on our own high-end servers.

Log inSign upStatic site hostingDiscord bot hostingBot guideSite APIsStatusReport abuseTermsPrivacy

© GG Studios · made with care, kept in orbit.