web: vite devサーバーのHost許可リストを設定
Coolifyの公開ドメイン(altdock.app.amania.jp)がvite 8のHostチェックで 403 Blocked requestになるため、VITE_ALLOWED_HOSTSで許可ホストを 環境変数から設定できるようにした。composeのデフォルトは altdock.app.amania.jp、カンマ区切り複数対応、* で全許可。
This commit is contained in:
+24
-3
@@ -11,6 +11,19 @@ const { d1, r2 } = hostingConfig;
|
||||
// macOS Seatbelt blocks FSEvents, so Codex previews need polling for HMR.
|
||||
const isCodexSeatbeltSandbox = process.env.CODEX_SANDBOX === "seatbelt";
|
||||
|
||||
// Vite 8 blocks unknown Host headers by default. In dev (incl. Coolify
|
||||
// proxying a public domain to the dev server) the public hosts must be
|
||||
// allow-listed. Accepts a comma-separated list, or "*"/"true" for any host.
|
||||
function parseAllowedHosts(raw: string | undefined): boolean | string[] | undefined {
|
||||
if (!raw) return undefined;
|
||||
const value = raw.trim();
|
||||
if (!value || value === "*" || value === "true") return true;
|
||||
return value
|
||||
.split(",")
|
||||
.map((host) => host.trim())
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
const localBindingConfig = {
|
||||
main: "./worker/index.ts",
|
||||
compatibility_flags: ["nodejs_compat"],
|
||||
@@ -43,10 +56,18 @@ export default defineConfig(async () => {
|
||||
// Wrangler snapshots its log path while the Cloudflare plugin is imported.
|
||||
const { cloudflare } = await import("@cloudflare/vite-plugin");
|
||||
|
||||
const allowedHosts = parseAllowedHosts(process.env.VITE_ALLOWED_HOSTS);
|
||||
|
||||
return {
|
||||
server: isCodexSeatbeltSandbox
|
||||
? { watch: { useFsEvents: false, usePolling: true } }
|
||||
: undefined,
|
||||
server:
|
||||
isCodexSeatbeltSandbox || allowedHosts
|
||||
? {
|
||||
...(isCodexSeatbeltSandbox
|
||||
? { watch: { useFsEvents: false, usePolling: true } }
|
||||
: {}),
|
||||
...(allowedHosts ? { allowedHosts } : {}),
|
||||
}
|
||||
: undefined,
|
||||
plugins: [
|
||||
vinext(),
|
||||
sites(),
|
||||
|
||||
Reference in New Issue
Block a user