Skip to content

Commit ad3edea

Browse files
committed
fix: env import and more ssr proxy paths
1 parent 72593df commit ad3edea

File tree

4 files changed

+44
-41
lines changed

4 files changed

+44
-41
lines changed

apps/desktop/vite.config.ts

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,43 @@ const isWebBuild = process.env.WEB_BUILD === "1"
4747
// eslint-disable-next-line no-console
4848
console.log(green("Build type:"), isWebBuild ? "Web" : "Unknown")
4949

50+
const proxyConfig = {
51+
target: "http://localhost:2234",
52+
changeOrigin: true,
53+
selfHandleResponse: true,
54+
configure: (proxy, _options) => {
55+
proxy.on("proxyRes", (proxyRes, req, res) => {
56+
const body = [] as any[]
57+
proxyRes.on("data", (chunk: any) => body.push(chunk))
58+
proxyRes.on("end", () => {
59+
const html = parseHTML(Buffer.concat(body).toString())
60+
const doc = html.document
61+
62+
const $scripts = doc.querySelectorAll("script")
63+
$scripts.forEach((script) => {
64+
const src = script.getAttribute("src")
65+
if (src) {
66+
script.setAttribute("src", `http://localhost:2234${src}`)
67+
}
68+
})
69+
70+
const $links = doc.querySelectorAll("link")
71+
$links.forEach((link) => {
72+
const href = link.getAttribute("href")
73+
if (href) {
74+
link.setAttribute("href", `http://localhost:2234${href}`)
75+
}
76+
})
77+
78+
res.setHeader("Content-Type", "text/html; charset=utf-8")
79+
80+
const modifiedHtml = doc.toString()
81+
res.end(modifiedHtml)
82+
})
83+
})
84+
},
85+
}
86+
5087
export default ({ mode }) => {
5188
const env = loadEnv(mode, process.cwd())
5289
const typedEnv = env as typeof EnvType
@@ -73,42 +110,10 @@ export default ({ mode }) => {
73110
},
74111
cors: true,
75112
proxy: {
76-
"/login": {
77-
target: "http://localhost:2234",
78-
changeOrigin: true,
79-
selfHandleResponse: true,
80-
configure: (proxy, _options) => {
81-
proxy.on("proxyRes", (proxyRes, req, res) => {
82-
const body = [] as any[]
83-
proxyRes.on("data", (chunk: any) => body.push(chunk))
84-
proxyRes.on("end", () => {
85-
const html = parseHTML(Buffer.concat(body).toString())
86-
const doc = html.document
87-
88-
const $scripts = doc.querySelectorAll("script")
89-
$scripts.forEach((script) => {
90-
const src = script.getAttribute("src")
91-
if (src) {
92-
script.setAttribute("src", `http://localhost:2234${src}`)
93-
}
94-
})
95-
96-
const $links = doc.querySelectorAll("link")
97-
$links.forEach((link) => {
98-
const href = link.getAttribute("href")
99-
if (href) {
100-
link.setAttribute("href", `http://localhost:2234${href}`)
101-
}
102-
})
103-
104-
res.setHeader("Content-Type", "text/html; charset=utf-8")
105-
106-
const modifiedHtml = doc.toString()
107-
res.end(modifiedHtml)
108-
})
109-
})
110-
},
111-
},
113+
"/login": proxyConfig,
114+
"/forget-password": proxyConfig,
115+
"/reset-password": proxyConfig,
116+
"/register": proxyConfig,
112117

113118
...(env.VITE_DEV_PROXY
114119
? {

packages/shared/src/env.desktop.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/**
22
* This env for apps/desktop
33
*/
4+
import { DEFAULT_VALUES } from "@follow/shared/env"
45
import { createEnv } from "@t3-oss/env-core"
56
import { z } from "zod"
67

7-
import { DEFAULT_VALUES } from "./env"
8-
98
export const env = createEnv({
109
clientPrefix: "VITE_",
1110
client: {

packages/shared/src/env.rn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* This env for apps/mobile
33
*/
4-
import { DEFAULT_VALUES } from "./env"
4+
import { DEFAULT_VALUES } from "@follow/shared/env"
55

66
const profile = "prod"
77

packages/shared/src/env.ssr.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/**
22
* This env for apps/ssr
33
*/
4+
import { DEFAULT_VALUES } from "@follow/shared/env"
45
import { createEnv } from "@t3-oss/env-core"
56
import { z } from "zod"
67

7-
import { DEFAULT_VALUES } from "./env"
8-
98
export const env = createEnv({
109
clientPrefix: "VITE_",
1110
client: {

0 commit comments

Comments
 (0)