mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
fix(docker): add cors support when using a custom endpoint
This commit is contained in:
parent
bc2518a369
commit
53d6adf299
1 changed files with 21 additions and 1 deletions
|
|
@ -3,6 +3,24 @@ import { NextResponse } from 'next/server';
|
||||||
export const config = {
|
export const config = {
|
||||||
matcher: '/:path*',
|
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) {
|
function customCollectEndpoint(req) {
|
||||||
const collectEndpoint = process.env.COLLECT_API_ENDPOINT;
|
const collectEndpoint = process.env.COLLECT_API_ENDPOINT;
|
||||||
|
|
@ -13,7 +31,9 @@ function customCollectEndpoint(req) {
|
||||||
|
|
||||||
if (pathname.endsWith(collectEndpoint)) {
|
if (pathname.endsWith(collectEndpoint)) {
|
||||||
url.pathname = '/api/send';
|
url.pathname = '/api/send';
|
||||||
return NextResponse.rewrite(url);
|
const resp = NextResponse.rewrite(url);
|
||||||
|
apiHeaders.forEach(({ key, value }) => resp.headers.append(key, value));
|
||||||
|
return resp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue