API functions
A file in api/ is an endpoint
Write api/hello.ts, export a GET, and push. It answers at /api/hello, on the same address as your site, with no server file to write and no CORS to set up.
Frameworks
One file a route
api/users.ts is /api/users, api/users/[id].ts is /api/users/:id, and api/files/[...path].ts takes the rest of the path.
Web-standard handlers
Export GET, POST, PUT, PATCH or DELETE taking a Request and returning a Response, or a default export with a fetch for every method.
Beside your front end
A Vite or Astro site, or plain HTML, is served from the same address, so the page and its API deploy together.
What homeport reads
- api/*.ts, *.js, *.mts, *.mjs
- Each file exporting a method is a route. Files and folders starting with _ are yours to share code from, and tests are left out.
- api/_middleware.ts
- Runs before every route. Return a Response to stop the request (a 401, say); return nothing to let it through.
- package.json
- Your dependencies, installed with the package manager your lockfile names. With no package.json at all, a project can be just its api/ folder.
- engines, .bun-version or .nvmrc
- Which runtime runs it, Bun or Node. With none of them, Node; with no package.json at all, Bun. Or pick one in the build settings.
- index.html, or a Vite or Astro build
- Your site, served for every path that isn’t /api, with fingerprinted files cached for a year.
What you get
- One small server for all your routes, built for you, on Node or Bun
- Route params handed to your handler, decoded
- Up to 5 minutes for a request, and bodies up to 32 MB
- An error is a plain 500 to the visitor, with the detail in your logs
- Postgres and storage in one click, their variables set for you
- You pay only while it’s in use, and nothing while nobody is using it
- HTTPS on a homeport.run address, and your own domain on paid plans
When you need more
Route params come in the second argument. A whole endpoint, in api/users/[id].ts:
export async function GET(req: Request, { params }: { params: { id: string } }) {
return Response.json({ id: params.id })
}