Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
fix(docker): add cors support when using a custom endpoint
Yo Sev53d6adf29998
diff --git a/docker/middleware.js b/docker/middleware.jsindex 85fe96d21..25fcc3489 100644--- a/docker/middleware.js+++ b/docker/middleware.js@@ -3,6 +3,24 @@ import { NextResponse } from 'next/server';export const config = {matcher: '/:path*',};+const apiHeaders = [+ {+ key: 'Access-Control-Allow-Origin',+ value: '*',+ },+ {+ key: 'Access-Control-Allow-Headers',+ value: '*',+ },+ {+ key: 'Access-Control-Allow-Methods',+ value: 'GET, DELETE, POST, PUT',+ },+ {+ key: 'Access-Control-Max-Age',+ value: process.env.CORS_MAX_AGE || '86400',+ },+];function customCollectEndpoint(req) {const collectEndpoint = process.env.COLLECT_API_ENDPOINT;@@ -13,7 +31,9 @@ function customCollectEndpoint(req) {if (pathname.endsWith(collectEndpoint)) {url.pathname = '/api/send';- return NextResponse.rewrite(url);+ const resp = NextResponse.rewrite(url);+ apiHeaders.forEach(({ key, value }) => resp.headers.append(key, value));+ return resp;}}}