forked from toniebox-reverse-engineering/teddycloud_web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
40 lines (36 loc) · 1.44 KB
/
vite.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
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import viteTsconfigPaths from "vite-tsconfig-paths";
import fs from "fs";
import path from "path";
export default defineConfig(({ command, mode }) => {
const portHttp = parseInt(process.env.VITE_APP_TEDDYCLOUD_PORT_HTTP || "3000", 10);
const portHttps = parseInt(process.env.VITE_APP_TEDDYCLOUD_PORT_HTTPS || "3443", 10);
const baseApiUrl = process.env.VITE_APP_TEDDYCLOUD_API_URL || "http://localhost";
const useHttps = process.env.HTTPS === "true";
const httpsOptions = useHttps
? {
key: fs.readFileSync(path.resolve(__dirname, "./localhost-key.pem")),
cert: fs.readFileSync(path.resolve(__dirname, "./localhost.pem")),
}
: undefined;
const targetUrl = useHttps ? `https://localhost:${portHttps}` : `http://localhost:${portHttp}`;
return {
base: "/web",
plugins: [react(), viteTsconfigPaths()],
server: {
open: true,
port: useHttps ? portHttps : portHttp,
host: true,
https: httpsOptions,
proxy: {
"/img_unknown.png": {
target: targetUrl,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/img_unknown\.png/, `${baseApiUrl}/web/img_unknown.png`),
secure: false,
},
},
},
};
});