13 lines
576 B
TypeScript
13 lines
576 B
TypeScript
const opencodeOrigin = /^https:\/\/([a-z0-9-]+\.)*opencode\.ai$/
|
|
|
|
export function isAllowedCorsOrigin(input: string | undefined, opts?: { cors?: string[] }) {
|
|
if (!input) return true
|
|
if (input.startsWith("http://localhost:")) return true
|
|
if (input.startsWith("http://127.0.0.1:")) return true
|
|
if (input.startsWith("oc://renderer")) return true
|
|
if (input === "tauri://localhost" || input === "http://tauri.localhost" || input === "https://tauri.localhost")
|
|
return true
|
|
if (opencodeOrigin.test(input)) return true
|
|
return opts?.cors?.includes(input) ?? false
|
|
}
|