Skip to content

Commit 598b51b

Browse files
committed
chore: bump version to 2.0.5 and add Cloudflare support
- Updated package version in package.json to 2.0.5. - Enhanced src/index.ts to detect Cloudflare environment and log runtime target. - Added Cloudflare-specific types to tsconfig.json. - Created wrangler.toml for Cloudflare deployment configuration, including D1 database and KV namespace bindings for caching.
1 parent 8c14e69 commit 598b51b

8 files changed

Lines changed: 1148 additions & 54 deletions

File tree

.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ APP_ENV=development
44

55
WARMUP_USERNAME=pphatdev
66

7+
# Cloudflare / Wrangler / D1
8+
# Used by drizzle.config.ts when running Drizzle commands against D1.
9+
# Keep these empty for local SQLite development.
10+
# CLOUDFLARE_ACCOUNT_ID=
11+
# CLOUDFLARE_D1_DATABASE_ID=
12+
# CLOUDFLARE_API_TOKEN=
13+
714
# Redis Cache Configuration (optional)
815
# If not set, defaults to redis://localhost:6379
916
# Redis is optional - the app will work with in-memory caching if Redis is unavailable

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ public/user/
1616

1717
# OS
1818
Thumbs.db
19+
20+
# Cloudflare
21+
.wrangler/
22+
.dev.vars

drizzle.config.ts

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,38 @@
11
import { defineConfig } from "drizzle-kit";
22

3-
export default defineConfig({
4-
schema: "./src/db/schema.ts",
5-
out: "./drizzle",
6-
dialect: "sqlite",
7-
dbCredentials: {
8-
url: "./data/stats.db",
9-
},
10-
});
3+
const env = (
4+
globalThis as unknown as {
5+
process?: { env?: Record<string, string | undefined> };
6+
}
7+
).process?.env ?? {};
8+
9+
const cloudflareAccountId = env.CLOUDFLARE_ACCOUNT_ID;
10+
const cloudflareDatabaseId = env.CLOUDFLARE_D1_DATABASE_ID;
11+
const cloudflareApiToken = env.CLOUDFLARE_API_TOKEN;
12+
13+
const useCloudflareD1 = Boolean(
14+
cloudflareAccountId && cloudflareDatabaseId && cloudflareApiToken,
15+
);
16+
17+
export default defineConfig(
18+
useCloudflareD1
19+
? {
20+
schema: "./src/db/schema.ts",
21+
out: "./drizzle",
22+
dialect: "sqlite",
23+
driver: "d1-http",
24+
dbCredentials: {
25+
accountId: cloudflareAccountId!,
26+
databaseId: cloudflareDatabaseId!,
27+
token: cloudflareApiToken!,
28+
},
29+
}
30+
: {
31+
schema: "./src/db/schema.ts",
32+
out: "./drizzle",
33+
dialect: "sqlite",
34+
dbCredentials: {
35+
url: "./data/stats.db",
36+
},
37+
},
38+
);

0 commit comments

Comments
 (0)