Skip to content

Commit f88e298

Browse files
committed
Update postgate env
1 parent fa6e5b0 commit f88e298

7 files changed

Lines changed: 43 additions & 39 deletions

File tree

.env.example

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
# Database
2-
POSTGRES_HOST=localhost
3-
POSTGRES_PORT=5432
4-
POSTGRES_USER=postgres
5-
POSTGRES_PASSWORD=password
6-
POSTGRES_DB=openworkers
1+
# Server
2+
PORT=7000
3+
NODE_ENV=development
74

85
# JWT (must be at least 32 characters)
96
JWT_ACCESS_SECRET=your-secret-key-here-must-be-at-least-32-chars-long
107
JWT_REFRESH_SECRET=your-refresh-secret-here-must-be-at-least-32-chars
11-
JWT_ACCESS_EXP=15m
12-
JWT_REFRESH_EXP=18h
138

149
# GitHub OAuth (optional)
1510
GITHUB_CLIENT_ID=your-github-oauth-app-client-id
1611
GITHUB_CLIENT_SECRET=your-github-oauth-app-client-secret
1712

18-
# Server
19-
PORT=7000
20-
NODE_ENV=development
13+
# Postgate (SQL proxy to PostgreSQL)
14+
POSTGATE_URL=http://localhost:6080
15+
POSTGATE_TOKEN=pg_your-token-here
16+
17+
# AI (optional)
18+
MISTRAL_API_KEY=your-mistral-api-key
19+
ANTHROPIC_API_KEY=your-anthropic-api-key
2120

22-
# Engine
23-
ENGINE_URL=http://localhost:8080
21+
# Shared Storage (S3-compatible object storage)
22+
SHARED_STORAGE_BUCKET=your-shared-storage-bucket-name
23+
SHARED_STORAGE_ENDPOINT=https://your-shared-storage-endpoint
24+
SHARED_STORAGE_ACCESS_KEY_ID=your-shared-storage-access-key-id
25+
SHARED_STORAGE_SECRET_ACCESS_KEY=your-shared-storage-secret-access-key
26+
SHARED_STORAGE_PUBLIC_URL=https://your-shared-storage-public-url

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openworkers-api",
3-
"version": "1.1.6",
3+
"version": "1.1.7",
44
"license": "MIT",
55
"module": "src/index.ts",
66
"type": "module",

src/config/index.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ const ConfigSchema = z.object({
3737
// Postgate (SQL proxy)
3838
postgate: z.object({
3939
url: z.string().url().default('http://localhost:6080'),
40-
// Admin token (pg_xxx format) - for managing databases and creating tokens
41-
adminToken: z.string().regex(/^pg_[a-f0-9]{64}$/, 'POSTGATE_ADMIN_TOKEN must be a valid pg_xxx token'),
42-
// OpenWorkers token (pg_xxx format) - for openworkers API database access
43-
openworkersToken: z.string().regex(/^pg_[a-f0-9]{64}$/, 'POSTGATE_OPENWORKERS_TOKEN must be a valid pg_xxx token')
40+
// Token (pg_xxx format) - for accessing OpenWorkers database
41+
token: z.string().regex(/^pg_[a-f0-9]{64}$/, 'POSTGATE_TOKEN must be a valid pg_xxx token')
4442
}),
4543

4644
// Shared S3/R2 for assets and storage bindings
@@ -87,8 +85,7 @@ function loadConfig(): Config {
8785
},
8886
postgate: {
8987
url: process.env.POSTGATE_URL,
90-
adminToken: process.env.POSTGATE_ADMIN_TOKEN,
91-
openworkersToken: process.env.POSTGATE_OPENWORKERS_TOKEN
88+
token: process.env.POSTGATE_TOKEN
9289
},
9390
sharedStorage: {
9491
bucket: process.env.SHARED_STORAGE_BUCKET,

src/index.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import kv from './routes/kv';
1313
import storage from './routes/storage';
1414
import ai from './routes/ai';
1515
import pkg from '../package.json';
16+
import { sql } from './services/db/client';
1617

1718
export const app = new Hono();
1819

@@ -24,11 +25,24 @@ if (nodeEnv === 'development') {
2425
app.use('*', cors());
2526
}
2627

28+
// API routes (no version prefix for health checks)
29+
const api = new Hono();
30+
2731
// Health check (no auth required)
28-
app.get('/health', (c) => {
32+
api.get('/health', (c) => {
2933
return c.json({ status: 'ok', timestamp: new Date().toISOString() });
3034
});
3135

36+
// Postgate connection test (no auth required)
37+
api.get('/postgate', async (c) => {
38+
try {
39+
const result = await sql<{ result: number }>('SELECT 1 + 1 AS result');
40+
return c.json({ status: 'ok', result: result[0]?.result });
41+
} catch (error) {
42+
return c.json({ status: 'error', error: String(error) }, 500);
43+
}
44+
});
45+
3246
// API v1 routes
3347
const v1 = new Hono();
3448

@@ -55,7 +69,8 @@ v1.route('/storage', storage);
5569
v1.route('/ai', ai);
5670
v1.route('/', users);
5771

58-
app.route('/api/v1', v1);
72+
api.route('/v1', v1);
73+
app.route('/api', api);
5974

6075
import { nodeEnv, port } from './config';
6176

src/services/db/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// Re-export from sql-client
2-
export { sql, createSqlClient, createAdminSqlClient, type PostgateSqlClient, type SqlResult } from './sql-client';
2+
export { sql, createSqlClient, type PostgateSqlClient, type SqlResult } from './sql-client';

src/services/db/sql-client.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,5 @@ export function createSqlClient(token: string): PostgateSqlClient {
8888
return createPostgateClientFromToken(postgateConfig.url, token);
8989
}
9090

91-
/**
92-
* Create a SQL client for the admin database (tenant management)
93-
* Uses the admin token from config
94-
*/
95-
export function createAdminSqlClient(): PostgateSqlClient {
96-
return createPostgateClientFromToken(postgateConfig.url, postgateConfig.adminToken);
97-
}
98-
99-
// Default export: openworkers database client (uses openworkers token)
100-
export const sql = createPostgateClientFromToken(postgateConfig.url, postgateConfig.openworkersToken);
91+
// Default SQL client for OpenWorkers database
92+
export const sql = createPostgateClientFromToken(postgateConfig.url, postgateConfig.token);

src/services/postgate.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,9 @@ interface CreateTokenResult {
7676

7777
/**
7878
* Admin client for postgate - manages tokens and databases via SQL
79-
* Uses admin token for authentication (access to public schema)
79+
* Uses the main token for authentication (access to public schema)
8080
*/
8181
export class PostgateAdminClient extends PostgateClient {
82-
constructor(baseUrl: string, adminToken: string) {
83-
super(baseUrl, adminToken);
84-
}
8582

8683
/**
8784
* Create a new token for a database using PL/pgSQL function
@@ -117,8 +114,8 @@ export class PostgateAdminClient extends PostgateClient {
117114
}
118115
}
119116

120-
// Admin client singleton - uses admin token from config
117+
// Admin client singleton - uses token from config
121118
export const postgateAdminClient = new PostgateAdminClient(
122119
postgateConfig.url,
123-
postgateConfig.adminToken
120+
postgateConfig.token
124121
);

0 commit comments

Comments
 (0)