Skip to content

Commit dd12a32

Browse files
committed
init
1 parent d25c0ad commit dd12a32

File tree

7 files changed

+208
-28
lines changed

7 files changed

+208
-28
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ yarn-error.log*
3838
# typescript
3939
*.tsbuildinfo
4040
next-env.d.ts
41+
42+
certificates

README.md

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,30 @@
1-
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
1+
# Next.js Local Docker Postgres setup
22

3-
## Getting Started
3+
This is a quick Next.js site to test the Local Docker with Vercel Postgres support. The [doc Vercel offers](https://vercel.com/docs/storage/vercel-postgres/local-development#local-development-with-vercel-postgres) is no longer up to date and the connection never works. This is due to the `@drizzle-orm` and `@vercel/postgres` uses different version of `@neondatabase/serverless` causes this. The only possible fix for now is to override the `@neondatabase/serverless` through `package.json`.
44

5-
First, run the development server:
5+
For `npm` user:
66

7-
```bash
8-
npm run dev
9-
# or
10-
yarn dev
11-
# or
12-
pnpm dev
13-
# or
14-
bun dev
7+
```json
8+
"overrides": {
9+
"@neondatabase/serverless": "0.10.4"
10+
}
1511
```
1612

17-
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
13+
For `pnpm` user:
1814

19-
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
20-
21-
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
22-
23-
## Learn More
24-
25-
To learn more about Next.js, take a look at the following resources:
26-
27-
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28-
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
29-
30-
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
15+
```json
16+
"pnpm": {
17+
"overrides": {
18+
"@neondatabase/serverless": "^0.10.4"
19+
}
20+
}
21+
```
3122

32-
## Deploy on Vercel
23+
`package-lock.json` or `pnpm-lock.yaml` needs to be remove and rebuild as well as the `node_modules`.
3324

34-
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
25+
## Resource
3526

36-
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
27+
- [Vercel GitHub issue](https://github.com/vercel/storage/issues/123#issuecomment-2500543485)
28+
- [Initial explanation](https://github.com/vercel/storage/issues/123#issuecomment-2500543485)
29+
- [Detailed blogpost](https://gal.hagever.com/posts/running-vercel-postgres-locally)
30+
- [Vercel blogpost](https://vercel.com/docs/storage/vercel-postgres/local-development#local-development-with-vercel-postgres)

app/api/test/route.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { sql } from "@/lib/db";
2+
3+
export const dynamic = "force-dynamic";
4+
5+
export async function GET() {
6+
// await sql.query(`CREATE TABLE users (name VARCHAR(255));`);
7+
// await sql.query(`INSERT INTO users (name) VALUES ('John Doe');`);
8+
const { rows, fields } = await sql.query(`SELECT * FROM users;`);
9+
10+
return Response.json({ success: true, rows, fields });
11+
}

docker-compose.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
services:
2+
postgres:
3+
image: postgres
4+
environment:
5+
POSTGRES_PASSWORD: password
6+
# Expose the Postgres port to the host machine,
7+
# so you can inspect and administrate it
8+
ports:
9+
- "54320:5432"
10+
pg_proxy:
11+
image: ghcr.io/neondatabase/wsproxy:latest
12+
platform: linux/arm64/v8
13+
environment:
14+
APPEND_PORT: "postgres:5432"
15+
ALLOW_ADDR_REGEX: ".*"
16+
LOG_TRAFFIC: "true"
17+
ports:
18+
# Expose the WebSocket proxy port to the host machine,
19+
# this is where @vercel/postgres will connect
20+
- "54330:80"
21+
depends_on:
22+
- postgres

lib/db.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { neonConfig } from "@neondatabase/serverless";
2+
3+
if (process.env.VERCEL_ENV === "development") {
4+
neonConfig.wsProxy = (host) => `${host}:54330/v1`;
5+
neonConfig.useSecureWebSocket = false;
6+
neonConfig.pipelineTLS = false;
7+
neonConfig.pipelineConnect = false;
8+
}
9+
10+
export * from "@vercel/postgres";

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "next-db-test",
2+
"name": "nextjs-local-docker-postgres-setup",
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
@@ -9,6 +9,8 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12+
"@neondatabase/serverless": "^0.10.4",
13+
"@vercel/postgres": "^0.10.0",
1214
"next": "15.0.3",
1315
"react": "19.0.0-rc-66855b96-20241106",
1416
"react-dom": "19.0.0-rc-66855b96-20241106"
@@ -22,5 +24,10 @@
2224
"postcss": "^8.4.49",
2325
"tailwindcss": "^3.4.15",
2426
"typescript": "^5.7.2"
27+
},
28+
"pnpm": {
29+
"overrides": {
30+
"@neondatabase/serverless": "^0.10.4"
31+
}
2532
}
2633
}

0 commit comments

Comments
 (0)