import { ConfigSchema, init_schema } from "../config/schema.js";
import { buildDefaultCorsOrigins } from "./host.js";
import { isNetworkAccessibleBindHost, resolveGatewayEffectiveHost } from "../config/gateway-bind.js";
//#region src/gateway/ensure-network-cors.ts
init_schema();
/** Ensure network-accessible binds have browser CORS origins (fail-closed startup guard). */
function ensureGatewayCorsOriginsForNetworkBind(config, port) {
	const bindHost = resolveGatewayEffectiveHost(config);
	if (!isNetworkAccessibleBindHost(bindHost)) return config;
	if ((config.gateway?.corsOrigins ?? []).map((origin) => origin.trim()).filter(Boolean).length > 0 || config.gateway?.dangerouslyAllowHostHeaderOriginFallback === true) return config;
	return ConfigSchema.parse({
		...config,
		gateway: {
			...config.gateway,
			corsOrigins: buildDefaultCorsOrigins({
				port,
				bindHost
			})
		}
	});
}
//#endregion
export { ensureGatewayCorsOriginsForNetworkBind };

//# sourceMappingURL=ensure-network-cors.js.map