Документація / Routes
Routes
Файлова маршрутизація. Шлях файлу — це URL.
Файлова маршрутизація. Кожен файл у app/routes/ стає URL.
| Файл | URL |
|---|---|
app/routes/index.ts | / |
app/routes/health.ts | /health |
app/routes/posts/[id].ts | /posts/:id |
app/routes/posts/[id]/publish.ts | /posts/:id/publish |
app/routes/files/[...path].ts | /files/* (catch-all) |
Один HTTP-метод на export:
// app/routes/posts/[id].ts
import { defineRoute } from '@hopak/core';
export const GET = defineRoute({
handler: async (ctx) => {
return { id: ctx.params.id };
},
});
export const POST = defineRoute({
handler: async (ctx) => {
const body = await ctx.body();
return { received: body };
},
});
default export трактується як GET.