Skip to main content

apps/gateway/src/middleware/security.ts

Metadata

Indexed Symbols

  • isProductionLike (line 9, function) - Implements is production like for module behavior.
  • isOriginAllowed (line 13, function) - Implements is origin allowed for module behavior.
  • getAllowedOrigins (line 20, function) - Implements get allowed origins for module behavior.

Markdown Headings (if applicable)

No markdown headings detected.

Source Preview

import type { FastifyPluginAsync } from "fastify";
import { env } from "../config/env.js";
import { getEffectivePlatformSettings } from "../services/runtime-config.js";

const ALLOWED_METHODS = "GET,POST,PUT,PATCH,DELETE,OPTIONS";
const ALLOWED_HEADERS =
"Authorization,Content-Type,Idempotency-Key,X-Correlation-Id,x-workspace-id,x-agentfield-signature,x-agentfield-delivery,x-hub-signature-256,x-github-delivery";

function isProductionLike(): boolean {
return env.nodeEnv === "production" || env.nodeEnv === "staging";
}

function isOriginAllowed(origin: string, allowedOrigins: string[]): boolean {
if (allowedOrigins.length === 0) {
return true;
}
return allowedOrigins.includes(origin);
}

async function getAllowedOrigins(): Promise<string[]> {
try {
const runtime = await getEffectivePlatformSettings();
return runtime.value.runtime.corsOrigins;
} catch {
return env.corsOrigins;