-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathalchemy.run.ts
More file actions
99 lines (88 loc) · 2.36 KB
/
alchemy.run.ts
File metadata and controls
99 lines (88 loc) · 2.36 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import alchemy from "alchemy";
import {
D1Database,
DurableObjectNamespace,
KVNamespace,
Vite,
Worker,
WranglerJson,
} from "alchemy/cloudflare";
const stage = process.env.ALCHEMY_STAGE || "dev";
const app = await alchemy("better-cloud", {
stage,
});
const db = await D1Database("database", {
name: `${app.name}-db`,
migrationsDir: "./src/server/db/migrations",
adopt: true,
readReplication: { mode: "auto" },
});
const sessions = await KVNamespace("sessions", {
title: "user-sessions",
adopt: true,
});
const counter = DurableObjectNamespace("counter", {
className: "Counter",
sqlite: true,
});
const connectionCounter = DurableObjectNamespace("connection-counter", {
className: "ConnectionCounter",
sqlite: false, // Connection counter doesn't need persistent storage
});
export const client = await Vite("client", {
name: `${app.name}-site`,
assets: "dist",
adopt: true,
bindings: {
VITE_CLIENT_URL: process.env.VITE_CLIENT_URL!,
VITE_SERVER_URL: process.env.VITE_SERVER_URL!,
},
domains: [
{
domainName: process.env.CUSTOM_WEB_DOMAIN!,
zoneId: process.env.CLOUDFLARE_ZONE_ID!,
adopt: true,
},
],
});
export const server = await Worker("server", {
name: `${app.name}-api`,
entrypoint: "src/server/index.ts",
compatibility: "node",
adopt: true,
bindings: {
DB: db,
SESSION_KV: sessions,
COUNTER: counter,
CONNECTION_COUNTER: connectionCounter,
ALCHEMY_STAGE: stage,
TRUSTED_ORIGINS: process.env.TRUSTED_ORIGINS!,
BETTER_AUTH_SECRET: alchemy.secret(process.env.BETTER_AUTH_SECRET!),
BETTER_AUTH_URL: process.env.BETTER_AUTH_URL!,
GOOGLE_CLIENT_ID: alchemy.secret(process.env.GOOGLE_CLIENT_ID!),
GOOGLE_CLIENT_SECRET: alchemy.secret(process.env.GOOGLE_CLIENT_SECRET!),
GITHUB_CLIENT_ID: alchemy.secret(process.env.GITHUB_CLIENT_ID!),
GITHUB_CLIENT_SECRET: alchemy.secret(process.env.GITHUB_CLIENT_SECRET!),
RESEND_API_KEY: alchemy.secret(process.env.RESEND_API_KEY!),
},
domains: [
{
domainName: process.env.CUSTOM_API_DOMAIN!,
zoneId: process.env.CLOUDFLARE_ZONE_ID!,
adopt: true,
},
],
dev: {
port: 8787,
},
});
if (stage === "prod") {
await WranglerJson({
worker: server,
path: "wrangler.jsonc",
});
console.log("\nDeployed via Alchemy:");
console.log(` Client -> https://${process.env.CUSTOM_WEB_DOMAIN}`);
console.log(` Server -> https://${process.env.CUSTOM_API_DOMAIN}`);
}
await app.finalize();