@rebasepro/cli 0.0.1-canary.1 → 0.0.1-canary.3263433
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/auth.d.ts +1 -0
- package/dist/commands/cli.test.d.ts +1 -0
- package/dist/commands/db.d.ts +1 -0
- package/dist/commands/dev.d.ts +1 -0
- package/dist/commands/dev.test.d.ts +1 -0
- package/dist/commands/doctor.d.ts +1 -0
- package/dist/commands/generate_sdk.d.ts +18 -0
- package/dist/commands/init.d.ts +4 -0
- package/dist/commands/init.test.d.ts +1 -0
- package/dist/commands/schema.d.ts +1 -0
- package/dist/index.cjs +1064 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.es.js +1066 -34
- package/dist/index.es.js.map +1 -1
- package/dist/utils/project.d.ts +45 -0
- package/dist/utils/project.test.d.ts +1 -0
- package/package.json +19 -11
- package/templates/template/.dockerignore +28 -0
- package/templates/template/.env.example +96 -0
- package/templates/template/README.md +84 -17
- package/templates/template/backend/Dockerfile +55 -10
- package/templates/template/backend/drizzle.config.ts +24 -4
- package/templates/template/backend/functions/hello.ts +52 -0
- package/templates/template/backend/package.json +30 -34
- package/templates/template/backend/src/env.ts +52 -0
- package/templates/template/backend/src/index.ts +113 -99
- package/templates/template/backend/tsconfig.json +1 -1
- package/templates/template/config/collections/authors.ts +45 -0
- package/templates/template/config/collections/index.ts +5 -0
- package/templates/template/config/collections/posts.ts +91 -0
- package/templates/template/config/collections/tags.ts +27 -0
- package/templates/template/config/package.json +28 -0
- package/templates/template/docker-compose.yml +49 -13
- package/templates/template/frontend/Dockerfile +36 -14
- package/templates/template/frontend/nginx.conf +40 -0
- package/templates/template/frontend/package.json +9 -10
- package/templates/template/frontend/src/App.tsx +24 -110
- package/templates/template/frontend/src/index.css +15 -1
- package/templates/template/frontend/src/main.tsx +2 -2
- package/templates/template/frontend/vite.config.ts +33 -3
- package/templates/template/package.json +12 -16
- package/templates/template/pnpm-workspace.yaml +4 -0
- package/templates/template/scripts/example.ts +91 -0
- package/templates/template/.env.template +0 -31
- package/templates/template/backend/scripts/db-generate.ts +0 -60
- package/templates/template/shared/collections/index.ts +0 -3
- package/templates/template/shared/collections/posts.ts +0 -53
- package/templates/template/shared/package.json +0 -28
- /package/templates/template/{shared → config}/index.ts +0 -0
- /package/templates/template/{shared → config}/tsconfig.json +0 -0
|
@@ -2,15 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
A [Rebase](https://rebase.pro) project with a PostgreSQL backend.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Quick Start
|
|
6
6
|
|
|
7
|
-
###
|
|
7
|
+
### Option 1: Docker (recommended for production)
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
cp .env.example .env
|
|
11
|
+
# Edit .env — set JWT_SECRET and DATABASE_URL (see comments for generators)
|
|
12
|
+
|
|
13
|
+
docker compose up -d
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
That's it. Your app is running:
|
|
17
|
+
- **Frontend**: http://localhost (port 80)
|
|
18
|
+
- **Backend API**: http://localhost:3001
|
|
19
|
+
- **PostgreSQL**: localhost:5432
|
|
20
|
+
|
|
21
|
+
### Option 2: Local Development
|
|
22
|
+
|
|
23
|
+
#### Prerequisites
|
|
8
24
|
|
|
9
25
|
- [Node.js](https://nodejs.org) >= 18
|
|
10
26
|
- [pnpm](https://pnpm.io)
|
|
11
27
|
- A PostgreSQL database
|
|
12
28
|
|
|
13
|
-
|
|
29
|
+
#### Setup
|
|
14
30
|
|
|
15
31
|
1. Install dependencies:
|
|
16
32
|
|
|
@@ -18,17 +34,18 @@ A [Rebase](https://rebase.pro) project with a PostgreSQL backend.
|
|
|
18
34
|
pnpm install
|
|
19
35
|
```
|
|
20
36
|
|
|
21
|
-
2. Configure
|
|
37
|
+
2. Configure environment:
|
|
22
38
|
|
|
23
|
-
```
|
|
24
|
-
|
|
39
|
+
```bash
|
|
40
|
+
cp .env.example .env
|
|
41
|
+
# Edit .env — set DATABASE_URL, JWT_SECRET
|
|
25
42
|
```
|
|
26
43
|
|
|
27
|
-
3. Generate and
|
|
44
|
+
3. Generate schema and push to database:
|
|
28
45
|
|
|
29
46
|
```bash
|
|
30
|
-
|
|
31
|
-
|
|
47
|
+
rebase schema generate
|
|
48
|
+
rebase db push
|
|
32
49
|
```
|
|
33
50
|
|
|
34
51
|
4. Start the dev server:
|
|
@@ -37,23 +54,73 @@ pnpm db:migrate
|
|
|
37
54
|
pnpm dev
|
|
38
55
|
```
|
|
39
56
|
|
|
40
|
-
|
|
57
|
+
Backend (Hono + PostgreSQL) on port 3001, frontend (Vite + React) on port 5173.
|
|
41
58
|
|
|
42
59
|
## Project Structure
|
|
43
60
|
|
|
44
61
|
```
|
|
45
|
-
├── frontend/
|
|
46
|
-
├──
|
|
47
|
-
|
|
48
|
-
├──
|
|
49
|
-
|
|
62
|
+
├── frontend/ # React frontend (Vite)
|
|
63
|
+
│ ├── Dockerfile # Production build → nginx
|
|
64
|
+
│ └── nginx.conf # SPA routing + compression
|
|
65
|
+
├── backend/ # Hono backend with PostgreSQL
|
|
66
|
+
│ ├── Dockerfile # Multi-stage production build
|
|
67
|
+
│ ├── functions/ # Custom API endpoints (auto-discovered)
|
|
68
|
+
│ └── src/
|
|
69
|
+
├── config/ # Shared collection definitions
|
|
70
|
+
│ └── collections/ # Schema-as-Code TypeScript files
|
|
71
|
+
├── docker-compose.yml # Production stack (Postgres + Backend + Frontend)
|
|
72
|
+
├── .env.example # Environment variable reference
|
|
73
|
+
└── package.json # Root workspace config
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Custom Functions
|
|
77
|
+
|
|
78
|
+
Drop a Hono app in `backend/functions/` and it's auto-mounted at `/api/functions/<name>`:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
// backend/functions/hello.ts
|
|
82
|
+
import { Hono } from "hono";
|
|
83
|
+
const app = new Hono();
|
|
84
|
+
app.post("/", async (c) => {
|
|
85
|
+
const body = await c.req.json();
|
|
86
|
+
return c.json({ message: `Hello, ${body.name}!` });
|
|
87
|
+
});
|
|
88
|
+
export default app;
|
|
50
89
|
```
|
|
51
90
|
|
|
91
|
+
Call from the client SDK: `client.call("functions/hello", { name: "World" })`
|
|
92
|
+
|
|
52
93
|
### Shared Collections
|
|
53
94
|
|
|
54
|
-
Collections are defined once in `
|
|
95
|
+
Collections are defined once in `config/collections/` and used by both the frontend and backend. This ensures your schema stays in sync across the stack.
|
|
96
|
+
|
|
97
|
+
## Environment Configuration
|
|
98
|
+
|
|
99
|
+
All configuration is managed through a single `.env` file in the project root. Both the backend and frontend read from this file:
|
|
100
|
+
|
|
101
|
+
- **Backend**: loads via `dotenv` from `../../.env` (relative to `backend/src/`)
|
|
102
|
+
- **Frontend**: Vite reads `VITE_*` variables via `envDir` pointing to the project root
|
|
103
|
+
- **Scripts**: load via `dotenv` from the project root
|
|
104
|
+
|
|
105
|
+
Copy `.env.example` to `.env` to get started. See the comments in `.env.example` for details on each variable.
|
|
106
|
+
|
|
107
|
+
## Production Deployment
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
# Build and start
|
|
111
|
+
docker compose up -d --build
|
|
112
|
+
|
|
113
|
+
# View logs
|
|
114
|
+
docker compose logs -f backend
|
|
115
|
+
|
|
116
|
+
# Stop
|
|
117
|
+
docker compose down
|
|
118
|
+
|
|
119
|
+
# Stop and remove data
|
|
120
|
+
docker compose down -v
|
|
121
|
+
```
|
|
55
122
|
|
|
56
123
|
## Documentation
|
|
57
124
|
|
|
58
125
|
- [Rebase Docs](https://rebase.pro/docs)
|
|
59
|
-
- [GitHub](https://github.com/
|
|
126
|
+
- [GitHub](https://github.com/rebasepro/rebase)
|
|
@@ -1,25 +1,70 @@
|
|
|
1
|
-
|
|
1
|
+
# ─── Multi-stage production Dockerfile for the Rebase backend ─────────
|
|
2
|
+
# Produces a minimal image (~150MB) with only the runtime needed.
|
|
3
|
+
#
|
|
4
|
+
# Build context: the project root (where pnpm-workspace.yaml lives)
|
|
5
|
+
# Usage:
|
|
6
|
+
# docker build -t my-app-backend -f backend/Dockerfile .
|
|
7
|
+
# docker run -p 3001:3001 --env-file .env my-app-backend
|
|
8
|
+
|
|
9
|
+
# ── Stage 1: Install + Build ─────────────────────────────────────────
|
|
10
|
+
FROM node:22-alpine AS builder
|
|
11
|
+
|
|
2
12
|
ENV PNPM_HOME="/pnpm"
|
|
3
13
|
ENV PATH="$PNPM_HOME:$PATH"
|
|
4
14
|
RUN corepack enable
|
|
15
|
+
|
|
16
|
+
# Native dependencies for bcrypt, pg, etc.
|
|
5
17
|
RUN apk add --no-cache python3 make g++
|
|
6
18
|
|
|
7
19
|
WORKDIR /app
|
|
8
20
|
|
|
9
|
-
# Copy root
|
|
10
|
-
COPY package.json ./
|
|
21
|
+
# Copy workspace root files first (cache-friendly layer)
|
|
22
|
+
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
|
|
11
23
|
|
|
12
|
-
# Copy
|
|
24
|
+
# Copy workspace packages
|
|
13
25
|
COPY backend ./backend
|
|
14
|
-
COPY
|
|
26
|
+
COPY config ./config
|
|
27
|
+
|
|
28
|
+
# Install all deps (including devDependencies for build)
|
|
29
|
+
RUN pnpm install --frozen-lockfile
|
|
30
|
+
|
|
31
|
+
# Build config first, then backend
|
|
32
|
+
RUN pnpm --filter "*-config" run build
|
|
33
|
+
RUN pnpm --filter "*-backend" run build
|
|
34
|
+
|
|
35
|
+
# Prune dev dependencies for a smaller runtime
|
|
36
|
+
RUN pnpm install --frozen-lockfile --prod
|
|
37
|
+
|
|
38
|
+
# ── Stage 2: Production Runtime ──────────────────────────────────────
|
|
39
|
+
FROM node:22-alpine AS runtime
|
|
40
|
+
|
|
41
|
+
ENV PNPM_HOME="/pnpm"
|
|
42
|
+
ENV PATH="$PNPM_HOME:$PATH"
|
|
43
|
+
ENV NODE_ENV=production
|
|
44
|
+
|
|
45
|
+
RUN corepack enable
|
|
15
46
|
|
|
16
|
-
#
|
|
17
|
-
RUN
|
|
47
|
+
# Security: run as non-root
|
|
48
|
+
RUN addgroup -g 1001 rebase && adduser -u 1001 -G rebase -s /bin/sh -D rebase
|
|
49
|
+
|
|
50
|
+
WORKDIR /app
|
|
18
51
|
|
|
19
|
-
#
|
|
20
|
-
|
|
21
|
-
|
|
52
|
+
# Copy only production artifacts
|
|
53
|
+
COPY --from=builder /app/package.json /app/pnpm-lock.yaml /app/pnpm-workspace.yaml ./
|
|
54
|
+
COPY --from=builder /app/node_modules ./node_modules
|
|
55
|
+
COPY --from=builder /app/backend ./backend
|
|
56
|
+
COPY --from=builder /app/config ./config
|
|
57
|
+
|
|
58
|
+
# Create uploads directory
|
|
59
|
+
RUN mkdir -p /app/backend/uploads && chown -R rebase:rebase /app
|
|
60
|
+
|
|
61
|
+
USER rebase
|
|
22
62
|
|
|
23
63
|
WORKDIR /app/backend
|
|
24
64
|
EXPOSE 3001
|
|
65
|
+
|
|
66
|
+
# Health check for orchestrators (Docker Compose, ECS, k8s)
|
|
67
|
+
HEALTHCHECK --interval=30s --timeout=5s --retries=3 --start-period=10s \
|
|
68
|
+
CMD wget --no-verbose --tries=1 --spider http://localhost:3001/health || exit 1
|
|
69
|
+
|
|
25
70
|
CMD ["pnpm", "start"]
|
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
import "dotenv
|
|
1
|
+
import * as dotenv from "dotenv";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
2
4
|
import { defineConfig } from "drizzle-kit";
|
|
3
5
|
import { tables } from "./src/schema.generated";
|
|
4
6
|
import { getTableName, Table } from "drizzle-orm";
|
|
5
7
|
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = path.dirname(__filename);
|
|
10
|
+
|
|
11
|
+
// Load .env from the project root (single file for the entire project)
|
|
12
|
+
dotenv.config({ path: path.resolve(__dirname, "../.env") });
|
|
13
|
+
|
|
6
14
|
if (!process.env.DATABASE_URL) {
|
|
7
15
|
throw new Error("DATABASE_URL is not set. Make sure .env file exists in the project root and contains DATABASE_URL");
|
|
8
16
|
}
|
|
9
17
|
|
|
10
|
-
// Extract table names from the generated schema
|
|
11
|
-
// This ensures drizzle-kit ONLY manages tables defined in the schema
|
|
18
|
+
// Extract table names from the generated schema.
|
|
19
|
+
// This ensures drizzle-kit ONLY manages tables defined in the schema.
|
|
20
|
+
// Any tables in the database that are NOT part of the Rebase schema are left untouched.
|
|
12
21
|
const tableNames = Object.values(tables).map(table => getTableName(table as Table));
|
|
13
22
|
|
|
14
23
|
export default defineConfig({
|
|
@@ -18,5 +27,16 @@ export default defineConfig({
|
|
|
18
27
|
dbCredentials: {
|
|
19
28
|
url: process.env.DATABASE_URL
|
|
20
29
|
},
|
|
21
|
-
|
|
30
|
+
// Only manage tables defined in the generated schema.
|
|
31
|
+
// Unmapped tables in the database are completely ignored.
|
|
32
|
+
tablesFilter: tableNames,
|
|
33
|
+
// Restrict drizzle-kit to the public schema only — tables in other schemas
|
|
34
|
+
// (e.g. extensions, custom schemas) are never touched.
|
|
35
|
+
schemaFilter: ["public"],
|
|
36
|
+
// Prevent drizzle-kit from managing roles not defined in the schema
|
|
37
|
+
entities: {
|
|
38
|
+
roles: false
|
|
39
|
+
},
|
|
40
|
+
// If PostGIS or other extensions create helper tables, ignore them
|
|
41
|
+
extensionsFilters: ["postgis"]
|
|
22
42
|
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import type { HonoEnv } from "@rebasepro/server-core";
|
|
3
|
+
import { rebase } from "@rebasepro/server-core";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Example custom function route.
|
|
7
|
+
*
|
|
8
|
+
* This file is auto-discovered by Rebase and mounted at:
|
|
9
|
+
* POST /api/functions/hello
|
|
10
|
+
* GET /api/functions/hello
|
|
11
|
+
*
|
|
12
|
+
* Call from the client SDK:
|
|
13
|
+
* const result = await client.call("functions/hello", { name: "World" });
|
|
14
|
+
*
|
|
15
|
+
* This is a standard Hono app — use any Hono middleware,
|
|
16
|
+
* define any HTTP methods, access the request/response directly.
|
|
17
|
+
*
|
|
18
|
+
* The `rebase` singleton gives you admin-level access to all
|
|
19
|
+
* app-scoped services (data, auth, storage, email) from anywhere.
|
|
20
|
+
* For request-scoped / RLS-scoped access, use c.get("user") and c.get("driver").
|
|
21
|
+
*/
|
|
22
|
+
const app = new Hono<HonoEnv>();
|
|
23
|
+
|
|
24
|
+
app.post("/", async (c) => {
|
|
25
|
+
const body = await c.req.json().catch(() => ({}));
|
|
26
|
+
const user = c.get("user");
|
|
27
|
+
|
|
28
|
+
const userId = (user && typeof user === "object" && "userId" in user)
|
|
29
|
+
? user.userId
|
|
30
|
+
: "anonymous";
|
|
31
|
+
|
|
32
|
+
// Access any Rebase service — just import and use:
|
|
33
|
+
// await rebase.email?.send({
|
|
34
|
+
// to: "admin@example.com",
|
|
35
|
+
// subject: "Function called",
|
|
36
|
+
// html: `<p>Hello from ${userId}!</p>`,
|
|
37
|
+
// });
|
|
38
|
+
//
|
|
39
|
+
// const authors = await rebase.data.authors.find({ limit: 5 });
|
|
40
|
+
|
|
41
|
+
return c.json({
|
|
42
|
+
message: `Hello, ${body.name || "World"}!`,
|
|
43
|
+
user: userId
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
app.get("/", (c) => {
|
|
48
|
+
return c.json({ status: "ok",
|
|
49
|
+
endpoint: "hello" });
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export default app;
|
|
@@ -1,36 +1,32 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"drizzle-kit": "^0.31.4",
|
|
33
|
-
"tsx": "^4.20.6",
|
|
34
|
-
"typescript": "^5.9.2"
|
|
35
|
-
}
|
|
2
|
+
"name": "{{PROJECT_NAME}}-backend",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Rebase backend with PostgreSQL",
|
|
5
|
+
"main": "src/index.ts",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "tsx watch --watch=\"../config/**/*\" src/index.ts",
|
|
9
|
+
"build": "tsc --noEmit",
|
|
10
|
+
"start": "tsx src/index.ts"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"{{PROJECT_NAME}}-config": "workspace:*",
|
|
14
|
+
"@rebasepro/server-core": "workspace:*",
|
|
15
|
+
"@rebasepro/server-postgresql": "workspace:*",
|
|
16
|
+
"drizzle-orm": "^0.44.4",
|
|
17
|
+
"hono": "^4.12.10",
|
|
18
|
+
"@hono/node-server": "^1.19.12",
|
|
19
|
+
"pg": "^8.11.3",
|
|
20
|
+
"ws": "^8.16.0",
|
|
21
|
+
"zod": "^3.22.4",
|
|
22
|
+
"dotenv": "^16.0.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/pg": "^8.6.5",
|
|
26
|
+
"@types/node": "^20.10.5",
|
|
27
|
+
"@types/ws": "^8.5.10",
|
|
28
|
+
"drizzle-kit": "^0.31.4",
|
|
29
|
+
"tsx": "^4.20.6",
|
|
30
|
+
"typescript": "^5.9.2"
|
|
31
|
+
}
|
|
36
32
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import * as dotenv from "dotenv";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = path.dirname(__filename);
|
|
8
|
+
|
|
9
|
+
dotenv.config({ path: path.resolve(__dirname, "../../.env") });
|
|
10
|
+
|
|
11
|
+
const envSchema = z.object({
|
|
12
|
+
NODE_ENV: z.enum(["development", "production", "test"]).default("development"),
|
|
13
|
+
PORT: z.string().default("3001").transform(Number),
|
|
14
|
+
DATABASE_URL: z.string().url("DATABASE_URL must be a valid URL"),
|
|
15
|
+
ADMIN_CONNECTION_STRING: z.string().url().optional(),
|
|
16
|
+
JWT_SECRET: z.string().min(32, "JWT_SECRET must be at least 32 characters long"),
|
|
17
|
+
JWT_ACCESS_EXPIRES_IN: z.string().default("1h"),
|
|
18
|
+
JWT_REFRESH_EXPIRES_IN: z.string().default("30d"),
|
|
19
|
+
GOOGLE_CLIENT_ID: z.string().optional(),
|
|
20
|
+
ALLOW_REGISTRATION: z.enum(["true", "false", ""]).default("false").transform(v => v === "true"),
|
|
21
|
+
CORS_ORIGINS: z.string().optional(),
|
|
22
|
+
FRONTEND_URL: z.string().optional(),
|
|
23
|
+
DB_POOL_MAX: z.string().default("20").transform(Number),
|
|
24
|
+
DB_POOL_IDLE_TIMEOUT: z.string().default("30000").transform(Number),
|
|
25
|
+
DB_POOL_CONNECT_TIMEOUT: z.string().default("10000").transform(Number),
|
|
26
|
+
FORCE_LOCAL_STORAGE: z.enum(["true", "false", ""]).optional().transform(v => v === "true"),
|
|
27
|
+
STORAGE_TYPE: z.enum(["local", "s3"]).default("local"),
|
|
28
|
+
STORAGE_PATH: z.string().optional(),
|
|
29
|
+
S3_BUCKET: z.string().optional(),
|
|
30
|
+
S3_REGION: z.string().optional(),
|
|
31
|
+
S3_ACCESS_KEY_ID: z.string().optional(),
|
|
32
|
+
S3_SECRET_ACCESS_KEY: z.string().optional(),
|
|
33
|
+
S3_ENDPOINT: z.string().url().optional(),
|
|
34
|
+
S3_FORCE_PATH_STYLE: z.enum(["true", "false", ""]).optional().transform(v => v === "true"),
|
|
35
|
+
/**
|
|
36
|
+
* Service key for admin-level script / server-to-server authentication.
|
|
37
|
+
* When set, scripts can send `Authorization: Bearer <key>` to get admin access.
|
|
38
|
+
* Generate with: node -e "console.log(require('crypto').randomBytes(48).toString('base64'))"
|
|
39
|
+
*/
|
|
40
|
+
REBASE_SERVICE_KEY: z.string().min(32, "REBASE_SERVICE_KEY must be at least 32 characters").optional()
|
|
41
|
+
}).superRefine((data, ctx) => {
|
|
42
|
+
if (data.NODE_ENV === "production" && !data.CORS_ORIGINS && !data.FRONTEND_URL) {
|
|
43
|
+
ctx.addIssue({
|
|
44
|
+
code: z.ZodIssueCode.custom,
|
|
45
|
+
message: "CORS_ORIGINS or FRONTEND_URL must be set in production to secure the API.",
|
|
46
|
+
path: ["CORS_ORIGINS"]
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Parse and export
|
|
52
|
+
export const env = envSchema.parse(process.env);
|