Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

fix(api): allow multiple cors origins

Carl-Gerhard Lindesvärd436e81ecc915
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts
index f6f429b5f..e960f0d96 100644
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@ -93,8 +93,19 @@ const startServer = async () => {
);
if (isPrivatePath) {
+ // Allow multiple dashboard domains
+ const allowedOrigins = [
+ process.env.NEXT_PUBLIC_DASHBOARD_URL,
+ ...(process.env.API_CORS_ORIGINS?.split(',') ?? []),
+ ].filter(Boolean);
+
+ const origin = req.headers.origin;
+ const isAllowed = origin && allowedOrigins.includes(origin);
+
+ logger.info('Allowed origins', { allowedOrigins, origin, isAllowed });
+
return callback(null, {
- origin: process.env.NEXT_PUBLIC_DASHBOARD_URL,
+ origin: isAllowed ? origin : false,
credentials: true,
});
}