-
Notifications
You must be signed in to change notification settings - Fork 0
/
astro.config.mjs
89 lines (85 loc) · 2.61 KB
/
astro.config.mjs
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
import { defineConfig } from "astro/config"
import react from "@astrojs/react"
import mdx from "@astrojs/mdx"
import dotenv from "dotenv"
console.log("NODE_ENV:", process.env.NODE_ENV)
dotenv.config({
path: [
".env",
".env.local",
`.env.${process.env.NODE_ENV}`,
`.env.${process.env.NODE_ENV}.local`,
],
debug: true,
override: true,
})
const WsApiTarget =
process.env.PUBLIC_IMPRESSO_WS_API_HOST ?? "http://localhost"
const WsApiPath = process.env.PUBLIC_IMPRESSO_WS_API_PATH ?? "/api/socket.io"
const PublicApiTarget =
process.env.PUBLIC_IMPRESSO_API_HOST ?? "http://localhost"
const PublicApiPath = process.env.PUBLIC_IMPRESSO_API_PATH ?? "/public-api/v1"
// these values are relevant only when the proxy is used with different paths, e.g; for a local instance of impresso middle layer
const ProxyPublicApiPath =
process.env.PUBLIC_IMPRESSO_API_PATH ?? "/public-api/v1"
const ProxyWsApiPath =
process.env.PUBLIC_IMPRESSO_WS_API_PATH ?? "/api/socket.io"
if (process.env.NODE_ENV === "development") {
console.log("WsApiTarget:", WsApiTarget)
console.log("WsApiPath:", WsApiPath)
console.log("PublicApiTarget:", PublicApiTarget)
console.log("PublicApiPath:", PublicApiPath)
console.log("ProxyPublicApiPath:", ProxyPublicApiPath)
console.log("ProxyWsApiPath:", ProxyWsApiPath)
}
// https://astro.build/config
export default defineConfig({
integrations: [react(), mdx()],
// legacy: {
// collections: true,
// },
site: process.env.PUBLIC_IMPRESSO_DATALAB_SITE || "http://localhost:4321",
base: process.env.PUBLIC_IMPRESSO_DATALAB_BASE || "/",
ssr: {
exclude: [WsApiPath, PublicApiPath],
},
vite: {
server: {
proxy: {
[WsApiPath]: {
target: `${WsApiTarget}${WsApiPath}`,
changeOrigin: true,
ws: true,
rewrite: (path) => {
const rewrittenPath = path
.replace(WsApiPath, ProxyWsApiPath)
.replace("//", "/")
console.log(
"[PROXY WS]",
path,
"->",
`${WsApiTarget}${rewrittenPath}`
)
return rewrittenPath
},
},
[PublicApiPath]: {
target: `${PublicApiTarget}`,
changeOrigin: true,
rewrite: (path) => {
const rewrittenPath = path
.replace(PublicApiPath, ProxyPublicApiPath)
.replace("//", "/")
console.log(
"[PROXY]",
path,
"->",
`${PublicApiTarget}${rewrittenPath}`
)
return rewrittenPath
},
},
},
},
},
})