mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
## Problem Studio's `routes/api/platform/projects/**` routes still run legacy Next Pages Router handlers through `compat/next/api.ts`, and `projects/$ref/config/index.ts` and `projects/$ref/billing/addons.ts` are unused in self-hosted mode. Part 5 of 7 for [FE-5114](https://linear.app/supabase/issue/FE-5114/rewrite-api-routes-as-native-tanstack-start-handlers-and-remove-the) migrates the 19 active project routes to native TanStack Start handlers and removes the 2 unused routes. ## Solution **Changed:** - Migrated 19 project routes — analytics (`endpoints/$name`, `log-drains`, `log-drains/$uuid`), API proxies (`api/graphql`, `api/rest`), content snippets & folders (`content/**`), and config/settings/databases/lints/keys/monitoring routes — to `createApiHandlers` - Preserved FE-5124 fixes on `log-drains/$uuid` (empty-body `204` on `DELETE`, `try`/`catch` + `!response.ok` → `500`); its `Allow: GET, PUT, DELETE` and the previously stale `Allow` on `log-drains` (`GET, POST`) now come from `createApiHandlers` - Forwarded upstream error status and JSON body (falling back to `500` / `{ error: { message } }`) in `api/graphql` and `api/rest` - Parsed the JSON body once in `content/index.ts` `PUT` so the `not found` create fallback does not attempt to re-read the request stream - `content/index.ts` and `content/folders/index.ts` read query params through `getSearchParamsRecord`, so repeated `ids` (and repeated GET params on `content/index`) return `400` as they did with Next's query parsing - `run-lints` forwards headers via `constructHeaders(Object.fromEntries(request.headers))` **Added:** - `getSearchParamsRecord` in `lib/api/apiHelpers.ts`: collects URL search params into a record, mapping repeated keys to arrays so zod string schemas reject them - `folderQueryParamsSchema` and `listFolderContents(request, folderId?)` in `lib/api/snippets.utils.ts`, shared by `content/folders/index` and `content/folders/$id` - `getLogflareConfig()` in `lib/api/self-hosted/logflare.ts`: reads the Logflare env vars at call time (same `500` naming the missing vars) and builds the request URLs and headers for `analytics/log-drains` and `analytics/log-drains/$uuid` - Unit tests for `getSearchParamsRecord`, `analytics/endpoints/$name`, `analytics/log-drains/$uuid`, `content/index`, `content/folders`, and `api/rest` (`HEAD` and upstream error forwarding) **Removed:** - Removed 2 unused routes (`routes/api/platform/projects/$ref/config/index.ts` and `routes/api/platform/projects/$ref/billing/addons.ts`) and regenerated `routeTree.gen.ts` **Behavior changes vs master:** - `analytics/endpoints/$name` GET strips `name` and `ref` from the forwarded query (parity with master, where they arrived as route params in `req.query`) - `content/folders` and `content/folders/$id` GET validate query params and return `400` for invalid or repeated values - `api/graphql` and `api/rest` forward upstream non-OK status codes and error bodies instead of always returning `500` - Unused `projects/$ref/config/index` and `projects/$ref/billing/addons` routes have been removed ## Review instructions 1. Run `pnpm --filter studio exec vitest run lib/api/apiHelpers.test.ts tests/routes/api/platform/projects/`. 2. On self-hosted Studio, create/update/delete a log drain, create/save/delete a SQL snippet and folder, and verify REST/GraphQL API docs load. ## Checklist - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [ ] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide) --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
/**
|
|
* Logflare connection details for the self-hosted log drain routes, read from the environment at
|
|
* call time. Returns a 500 `Response` naming the missing env vars when either is unset.
|
|
*
|
|
* _Only call this from server-side self-hosted code._
|
|
*/
|
|
export function getLogflareConfig() {
|
|
const { LOGFLARE_PRIVATE_ACCESS_TOKEN: token, LOGFLARE_URL: baseUrl } = process.env
|
|
if (!token || !baseUrl) {
|
|
const missingEnvVars = [
|
|
token ? null : 'LOGFLARE_PRIVATE_ACCESS_TOKEN',
|
|
baseUrl ? null : 'LOGFLARE_URL',
|
|
].filter(Boolean)
|
|
return Response.json(
|
|
{ error: { message: `${missingEnvVars.join(', ')} env variables are not set` } },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
|
|
return {
|
|
/** A Logflare API URL with `pathname` set via `URL.pathname`, so route params stay in the path. */
|
|
url: (pathname: string) => {
|
|
const url = new URL(baseUrl)
|
|
url.pathname = pathname
|
|
return url
|
|
},
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
'Content-Type': 'application/json',
|
|
Accept: 'application/json',
|
|
},
|
|
}
|
|
}
|