-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.config.ts
55 lines (46 loc) · 1.26 KB
/
app.config.ts
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
import { join } from "node:path";
import { defineConfig } from "@tanstack/start/config";
import type { App } from "vinxi";
import tsConfigPaths from "vite-tsconfig-paths";
import { getCloudflareProxyEnv, isInCloudflareCI } from "./app/libs/cloudflare";
import { parseEnv } from "./app/libs/env";
await parseEnv();
const app = defineConfig({
server: {
preset: "cloudflare-pages",
rollupConfig: {
external: ["node:async_hooks"],
},
},
vite: {
define: await proxyCloudflareEnv(),
plugins: [
tsConfigPaths({
projects: ["./tsconfig.json"],
}),
],
},
});
async function proxyCloudflareEnv() {
if (isInCloudflareCI()) return undefined;
const env = await getCloudflareProxyEnv();
const viteDefine = Object.fromEntries(
Object.entries(env)
.filter(([key]) => key.startsWith("VITE_"))
.map(([key, value]) => [`import.meta.env.${key}`, `"${value}"`]),
);
return viteDefine;
}
function withGlobalMiddleware(app: App) {
return {
...app,
config: {
...app.config,
routers: app.config.routers.map((router) => ({
...router,
middleware: router.target !== "server" ? undefined : join("app", "global-middleware.ts"),
})),
},
};
}
export default withGlobalMiddleware(app);