mirror of
https://github.com/supabase/supabase.git
synced 2026-10-10 11:55:05 +03:00
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## Problem The Docs E2E link checker found broken links throughout docs, starting with `phone-login.mdx` pointing to `/docs/guides/cli/config` (404). Old links like `/docs/guides/cli/config` still work on the live site because `supabase.com` has redirects set up for them, but these links break on the docs preview site, which is what the E2E check tests against. These issues look clean on the live site, and I didn't catch them in my first pass because I was testing production instead of the preview. The E2E check only tests the ~20 pages a given PR happens to touch, so fixing the pages it flagged kept exposing more of the same problem one page at a time as each fix pulled in a new file. To stop chasing this incrementally, I cross-referenced every `/docs/guides/*` and `/docs/reference/*` redirect source in `apps/www/lib/redirects.js` against actual usage across all of `apps/docs`, and verified each candidate against the live preview. ## Solution Rather than updating the Docs E2E link checker, this PR resolves the links. **Why:** we own these docs, so keeping the links clean without redirects is keeping the house maintained. See [Broken Window Theory](https://blog.codinghorror.com/the-broken-window-theory/). Updated every link still using an old path to point straight at the current page instead of relying on a redirect. This covers old links like: - `/docs/guides/cli/config` → `/docs/guides/local-development/cli/config` - `/docs/guides/cli/getting-started` → `/docs/guides/local-development/cli/getting-started` - `/docs/guides/cli/local-development` → `/docs/guides/local-development/database-migrations` - `/docs/guides/cli/managing-environments` → `/docs/guides/deployment/managing-environments` - `/docs/guides/cli/seeding-your-database` → `/docs/guides/local-development/seeding-your-database` - bare `/docs/guides/cli` → `/docs/guides/local-development` - `/docs/guides/platform/compute-add-ons` → `/docs/guides/platform/compute-and-disk` - `/docs/guides/platform/shared-responsibility-model` → `/docs/guides/deployment/shared-responsibility-model` - `/docs/guides/database` → `/docs/guides/database/overview` - `/docs/reference/javascript`, `/docs/reference/dart`, `/docs/reference/kotlin`, `/docs/reference/python`, `/docs/reference/csharp` → their `/introduction` pages (the redirect's own destination, `/start`, turned out to be dead even on production — a separate bug in `redirects.js` I didn't touch here) - and about 35 more of the same pattern, listed in the commit messages Also fixed a handful of dead heading anchors found along the way (links that resolve to the right page but point at a `#section` that got renamed or moved), including the original `#bigquery` anchor and a few in `connecting-to-postgres.mdx` where content moved to its own dedicated page. Left alone on purpose: - `content/guides/cli.mdx` — this page has no route in the docs app at all (no `app/guides/cli/` directory), so it 404s even in production before the `www` redirect ever fires. Fixing its internal link wouldn't change that; it needs an actual routing/content decision, not a link fix. - A few candidates that already resolve fine as-is (`pg_partman`, bare `/docs/reference/api`, bare `/docs/reference/cli`) — confirmed via curl, left untouched. ## Manual testing 1. Confirmed every new link target actually exists by checking the destination file/page and matching heading anchors. 2. Cross-referenced every `/docs/guides/*` and `/docs/reference/*` redirect source in `apps/www/lib/redirects.js` against real usage in `apps/docs`, and curl-verified each old path (404) and new path (200) against the live PR preview before fixing it. 3. Ran the Docs E2E link checker locally against changed pages. 4. Spot-checked the original broken link from CI (`/docs/guides/cli/config`) to confirm it now points to a working page.
137 lines
5.4 KiB
Plaintext
137 lines
5.4 KiB
Plaintext
---
|
|
id: 'serverless-drivers'
|
|
title: 'Serverless Drivers'
|
|
description: 'Connecting to your Postgres database in serverless environments.'
|
|
subtitle: 'Connecting to your Postgres database in serverless environments.'
|
|
---
|
|
|
|
Supabase provides several options for connecting to your Postgres database from serverless environments.
|
|
|
|
[supabase-js](/docs/reference/javascript/introduction) is an isomorphic JavaScript client that uses the [auto-generated REST API](/docs/guides/api) and therefore works in any environment that supports HTTPS connections. This API has a built-in [connection pooler](/docs/guides/database/connecting-to-postgres#poolers) and can serve thousands of simultaneous requests, and therefore is ideal for Serverless workloads.
|
|
|
|
## Vercel Edge Functions
|
|
|
|
Vercel's [Edge runtime](https://vercel.com/docs/functions/runtimes/edge-runtime) is built on top of the [V8 engine](https://v8.dev/), that provides a limited set of Web Standard APIs.
|
|
|
|
### Quickstart
|
|
|
|
Choose one of these Vercel Deploy Templates which use our [Vercel Deploy Integration](https://vercel.com/integrations/supabase) to automatically configure your connection strings as environment variables on your Vercel project!
|
|
|
|
<div>
|
|
<div className="grid grid-cols-12 gap-6 not-prose">
|
|
<Link
|
|
href="https://supabase.link/nextjs-with-supabase-starter"
|
|
className="col-span-12 md:col-span-4"
|
|
passHref
|
|
>
|
|
<GlassPanel title="supabase-js" hasLightIcon={true} background={false} showIconBg={true}>
|
|
A Next.js App Router template configured with cookie-based auth using Supabase, TypeScript
|
|
and Tailwind CSS.
|
|
</GlassPanel>
|
|
</Link>
|
|
<Link
|
|
href="https://supabase.link/nextjs-supabase-kysely"
|
|
className="col-span-12 md:col-span-4"
|
|
passHref
|
|
>
|
|
<GlassPanel title="Kysely" hasLightIcon={true} background={false} showIconBg={true}>
|
|
Basic Next.js template that uses Supabase as the database and Kysely as the query builder.
|
|
</GlassPanel>
|
|
</Link>
|
|
</div>
|
|
</div>
|
|
|
|
### Manual configuration
|
|
|
|
In your [`Database Settings`](/dashboard/project/_?showConnect=true&method=transaction) and copy the URI from the `Transaction pooler` section and save it as the `POSTGRES_URL` environment variable. Remember to replace the password placeholder with your actual database password and add the following suffix `?workaround=supabase-pooler.vercel`.
|
|
|
|
```txt .env.local
|
|
POSTGRES_URL="postgres://postgres.cfcxynqnhdybqtbhjemm:[YOUR-PASSWORD]@aws-0-ap-southeast-1.pooler.supabase.com:6543/postgres?workaround=supabase-pooler.vercel"
|
|
```
|
|
|
|
<Tabs scrollable defaultActiveId="drizzle" type="underlined" size="small">
|
|
|
|
<TabPanel id="drizzle" label="Drizzle">
|
|
|
|
```ts lib/drizzle.ts
|
|
import { sql } from '@vercel/postgres'
|
|
import { InferInsertModel, InferSelectModel } from 'drizzle-orm'
|
|
import { pgTable, serial, text, timestamp, uniqueIndex } from 'drizzle-orm/pg-core'
|
|
import { drizzle } from 'drizzle-orm/vercel-postgres'
|
|
|
|
export const UsersTable = pgTable(
|
|
'users',
|
|
{
|
|
id: serial('id').primaryKey(),
|
|
name: text('name').notNull(),
|
|
email: text('email').notNull(),
|
|
image: text('image').notNull(),
|
|
createdAt: timestamp('createdAt').defaultNow().notNull(),
|
|
},
|
|
(users) => {
|
|
return {
|
|
uniqueIdx: uniqueIndex('unique_idx').on(users.email),
|
|
}
|
|
}
|
|
)
|
|
|
|
export type User = InferSelectModel<typeof UsersTable>
|
|
export type NewUser = InferInsertModel<typeof UsersTable>
|
|
|
|
// Connect to Vercel Postgres
|
|
export const db = drizzle(sql)
|
|
```
|
|
|
|
</TabPanel>
|
|
<TabPanel id="kysely" label="Kysely">
|
|
|
|
```ts lib/kysely.ts
|
|
import { createKysely } from '@vercel/postgres-kysely'
|
|
import { ColumnType, Generated } from 'kysely'
|
|
|
|
interface UserTable {
|
|
// Columns that are generated by the database should be marked
|
|
// using the `Generated` type. This way they are automatically
|
|
// made optional in inserts and updates.
|
|
id: Generated<number>
|
|
name: string
|
|
email: string
|
|
image: string
|
|
|
|
// You can specify a different type for each operation (select, insert and
|
|
// update) using the `ColumnType<SelectType, InsertType, UpdateType>`
|
|
// wrapper. Here we define a column `createdAt` that is selected as
|
|
// a `Date`, can optionally be provided as a `string` in inserts and
|
|
// can never be updated:
|
|
createdAt: ColumnType<Date, string | undefined, never>
|
|
}
|
|
|
|
// Keys of this interface are table names.
|
|
export interface Database {
|
|
users: UserTable
|
|
}
|
|
|
|
export const db = createKysely<Database>()
|
|
export { sql } from 'kysely'
|
|
```
|
|
|
|
</TabPanel>
|
|
</Tabs>
|
|
|
|
## Cloudflare Workers
|
|
|
|
Cloudflare's Workers runtime also uses the [V8 engine](https://v8.dev/) but provides polyfills for a subset of Node.js APIs and [TCP Sockets API](https://developers.cloudflare.com/workers/runtime-apis/tcp-sockets/), giving you a couple of options:
|
|
|
|
- [supabase-js](https://developers.cloudflare.com/workers/databases/native-integrations/supabase/)
|
|
- [Postgres.js](https://github.com/porsager/postgres?tab=readme-ov-file#cloudflare-workers-support)
|
|
- [node-postgres](https://developers.cloudflare.com/workers/tutorials/postgres/)
|
|
|
|
## Supabase Edge Functions
|
|
|
|
Supabase Edge Functions uses the [Deno runtime](https://deno.com/) which has native support for TCP connections allowing you to choose your favorite client:
|
|
|
|
- [supabase-js](/docs/guides/functions/connect-to-postgres#using-supabase-js)
|
|
- [Deno Postgres driver](/docs/guides/functions/connect-to-postgres#using-a-postgres-client)
|
|
- [Postgres.js](https://github.com/porsager/postgres)
|
|
- [Drizzle](/docs/guides/functions/connect-to-postgres#using-drizzle)
|