-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnitro.config.ts
More file actions
115 lines (109 loc) · 2.68 KB
/
Copy pathnitro.config.ts
File metadata and controls
115 lines (109 loc) · 2.68 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { defineNitroConfig } from "nitro/config";
const storageDriver = process.env.XYRA_STORAGE_DRIVER ?? "kv";
const kvBindingNames = {
pastes: process.env.XYRA_PASTES_KV_BINDING ?? "KV_PASTES",
meta: process.env.XYRA_PASTES_META_KV_BINDING ?? "KV_PASTES_META",
ratelimits: process.env.XYRA_RATELIMITS_KV_BINDING ?? "KV_RATELIMITS",
};
const defaultKvNamespaceId =
process.env.XYRA_DEFAULT_KV_ID ?? "ca398e05df154f6981f8ae49a12c2c2d";
const kvNamespaceIds = {
pastes: process.env.XYRA_PASTES_KV_ID ?? defaultKvNamespaceId,
meta:
process.env.XYRA_PASTES_META_KV_ID ??
process.env.XYRA_PASTES_KV_ID ??
defaultKvNamespaceId,
ratelimits:
process.env.XYRA_RATELIMITS_KV_ID ??
process.env.XYRA_PASTES_KV_ID ??
defaultKvNamespaceId,
};
const fsStorage = {
pastes: {
driver: "fs",
base: ".data/pastes",
},
"pastes:meta": {
driver: "fs",
base: ".data/meta",
},
ratelimits: {
driver: "fs",
base: ".data/ratelimits",
},
};
const kvStorage = {
pastes: {
driver: "cloudflare-kv-binding",
binding: kvBindingNames.pastes,
},
"pastes:meta": {
driver: "cloudflare-kv-binding",
binding: kvBindingNames.meta,
},
ratelimits: {
driver: "cloudflare-kv-binding",
binding: kvBindingNames.ratelimits,
},
};
const storage = storageDriver === "fs" ? fsStorage : kvStorage;
const devStorage = storageDriver === "fs" ? undefined : fsStorage;
const pruneCron = process.env.XYRA_PRUNE_CRON ?? "*/10 * * * *";
const kvNamespaces = Object.entries(kvBindingNames)
.map(([key, binding]) => {
const id = kvNamespaceIds[key as keyof typeof kvNamespaceIds];
return id
? {
binding,
id,
}
: null;
})
.filter(Boolean) as Array<{ binding: string; id: string }>;
export default defineNitroConfig({
compatibilityDate: "2024-12-18",
preset: "cloudflare_module",
serverDir: "server",
errorHandler: "./server/error",
experimental: {
tasks: true,
},
cloudflare: {
deployConfig: true,
nodeCompat: true,
wrangler: {
name: "xyra-paste",
kv_namespaces: kvNamespaces,
},
},
runtimeConfig: {
paste: {
rateLimit: {
windowMs: Number(process.env.XYRA_RATE_LIMIT_WINDOW_MS ?? 60_000),
maxRequests: Number(process.env.XYRA_RATE_LIMIT_MAX ?? 120),
},
},
public: {
paste: {
defaultKey: process.env.XYRA_UI_DEFAULT_KEY || "",
},
},
},
routeRules: {
"/api/**": {
headers: {
"cache-control": "no-store",
},
},
"/p/**": {
headers: {
"cache-control": "no-store",
},
},
},
scheduledTasks: {
[pruneCron]: ["prune-expired"],
},
storage,
devStorage,
});