mirror of
https://github.com/tiennm99/loto.git
synced 2026-10-11 12:19:05 +00:00
Symptom: 'Blocked request. This host (codeserver.sg.miti99.com) is not allowed.' — the configs were reading process.env.CODESERVER_HOST, which is empty at config-eval time because Vite reads .env.local at runtime, not into process.env. Switch both vite.config.js and svelte.config.js to use loadEnv() from vite, which reads .env.local explicitly. Also lift allowedHosts out of the codeserver profile so plain `npm run dev` is also reachable from the codeserver proxy when CODESERVER_HOST is set in .env.local.
35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
import { sveltekit } from "@sveltejs/kit/vite";
|
|
import tailwindcss from "@tailwindcss/vite";
|
|
import { defineConfig, loadEnv } from "vite";
|
|
|
|
export default defineConfig(({ mode }) => {
|
|
// .env.local lives outside process.env at config-eval time; loadEnv reads it.
|
|
const env = loadEnv(mode, process.cwd(), "");
|
|
const isCodeserver = process.env.VITE_DEV_PROFILE === "codeserver";
|
|
const host = env.CODESERVER_HOST;
|
|
const port = Number(env.CODESERVER_PORT ?? 3000);
|
|
|
|
return {
|
|
plugins: [tailwindcss(), sveltekit()],
|
|
server: {
|
|
port,
|
|
host: true,
|
|
strictPort: true,
|
|
// Always allow the codeserver host if .env.local sets one — covers
|
|
// both `npm run dev` (no proxy config) and `npm run dev:codeserver`.
|
|
...(host ? { allowedHosts: [host] } : {}),
|
|
// HMR through the proxy only in the explicit codeserver profile.
|
|
...(isCodeserver && host
|
|
? {
|
|
hmr: {
|
|
host,
|
|
protocol: "wss",
|
|
clientPort: 443,
|
|
path: `/absproxy/${port}/`,
|
|
},
|
|
}
|
|
: {}),
|
|
},
|
|
};
|
|
});
|