mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Update Docker middleware
This commit is contained in:
parent
acbcd05190
commit
7f9f4957d3
1 changed files with 14 additions and 22 deletions
|
|
@ -3,24 +3,18 @@ import { NextResponse } from 'next/server';
|
||||||
export const config = {
|
export const config = {
|
||||||
matcher: '/:path*',
|
matcher: '/:path*',
|
||||||
};
|
};
|
||||||
const apiHeaders = [
|
|
||||||
{
|
const apiHeaders = {
|
||||||
key: 'Access-Control-Allow-Origin',
|
'Access-Control-Allow-Origin': '*',
|
||||||
value: '*',
|
'Access-Control-Allow-Headers': '*',
|
||||||
},
|
'Access-Control-Allow-Methods': 'GET, DELETE, POST, PUT',
|
||||||
{
|
'Access-Control-Max-Age': process.env.CORS_MAX_AGE || '86400',
|
||||||
key: 'Access-Control-Allow-Headers',
|
};
|
||||||
value: '*',
|
|
||||||
},
|
const trackerHeaders = {
|
||||||
{
|
'Access-Control-Allow-Origin': '*',
|
||||||
key: 'Access-Control-Allow-Methods',
|
'Cache-Control': 'public, max-age=86400, must-revalidate',
|
||||||
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;
|
||||||
|
|
@ -31,9 +25,7 @@ function customCollectEndpoint(req) {
|
||||||
|
|
||||||
if (pathname.endsWith(collectEndpoint)) {
|
if (pathname.endsWith(collectEndpoint)) {
|
||||||
url.pathname = '/api/send';
|
url.pathname = '/api/send';
|
||||||
const resp = NextResponse.rewrite(url);
|
return NextResponse.rewrite(url, { headers: apiHeaders });
|
||||||
apiHeaders.forEach(({ key, value }) => resp.headers.append(key, value));
|
|
||||||
return resp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -48,7 +40,7 @@ function customScriptName(req) {
|
||||||
|
|
||||||
if (names.find(name => pathname.endsWith(name))) {
|
if (names.find(name => pathname.endsWith(name))) {
|
||||||
url.pathname = '/script.js';
|
url.pathname = '/script.js';
|
||||||
return NextResponse.rewrite(url);
|
return NextResponse.rewrite(url, { headers: trackerHeaders });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue