mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-03 15:43:45 +00:00
feat(core): configurable cors hosts
This commit is contained in:
@@ -17,6 +17,12 @@ const options = {
|
||||
describe: "enable mDNS service discovery (defaults hostname to 0.0.0.0)",
|
||||
default: false,
|
||||
},
|
||||
cors: {
|
||||
type: "string" as const,
|
||||
array: true,
|
||||
describe: "additional domains to allow for CORS",
|
||||
default: [] as string[],
|
||||
},
|
||||
}
|
||||
|
||||
export type NetworkOptions = InferredOptionTypes<typeof options>
|
||||
@@ -30,6 +36,7 @@ export async function resolveNetworkOptions(args: NetworkOptions) {
|
||||
const portExplicitlySet = process.argv.includes("--port")
|
||||
const hostnameExplicitlySet = process.argv.includes("--hostname")
|
||||
const mdnsExplicitlySet = process.argv.includes("--mdns")
|
||||
const corsExplicitlySet = process.argv.includes("--cors")
|
||||
|
||||
const mdns = mdnsExplicitlySet ? args.mdns : (config?.server?.mdns ?? args.mdns)
|
||||
const port = portExplicitlySet ? args.port : (config?.server?.port ?? args.port)
|
||||
@@ -38,6 +45,9 @@ export async function resolveNetworkOptions(args: NetworkOptions) {
|
||||
: mdns && !config?.server?.hostname
|
||||
? "0.0.0.0"
|
||||
: (config?.server?.hostname ?? args.hostname)
|
||||
const configCors = config?.server?.cors ?? []
|
||||
const argsCors = Array.isArray(args.cors) ? args.cors : args.cors ? [args.cors] : []
|
||||
const cors = [...configCors, ...argsCors]
|
||||
|
||||
return { hostname, port, mdns }
|
||||
return { hostname, port, mdns, cors }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user