Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

export.ts

28 lines830 Bytes

1import { createFileRoute } from '@tanstack/react-router'
2import { env } from 'cloudflare:workers'
3​
4import { getDb } from '#/db/index.ts'
5import { isAdminRequest, jsonError } from '#/server/admin.ts'
6import { exportCatalogStream } from '#/server/export.ts'
7​
8export const Route = createFileRoute('/v1/admin/export')({
9 server: {
10 handlers: {
11 GET: async ({ request }) => {
12 if (!isAdminRequest(request, env.ADMIN_KEY)) {
13 return jsonError(
14 401,
15 'unauthorized',
16 'Provide the admin key via X-Admin-Key or Authorization: Bearer.',
17 )
18 }
19 return new Response(exportCatalogStream(getDb(env)), {
20 headers: {
21 'Content-Type': 'application/json',
22 'Cache-Control': 'no-store',
23 },
24 })
25 },
26 },
27 },
28})