mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-06 01:15:42 +01:00
Merge pull request #2965 from peter-kuhmann/add-cors-header-for-tracker-script
Add "Access-Control-Allow-Origin" header for tracker script.
This commit is contained in:
commit
1f52b49ea9
@ -24,7 +24,7 @@ const contentSecurityPolicy = [
|
|||||||
`frame-ancestors 'self' ${frameAncestors}`,
|
`frame-ancestors 'self' ${frameAncestors}`,
|
||||||
];
|
];
|
||||||
|
|
||||||
const headers = [
|
const defaultHeaders = [
|
||||||
{
|
{
|
||||||
key: 'X-DNS-Prefetch-Control',
|
key: 'X-DNS-Prefetch-Control',
|
||||||
value: 'on',
|
value: 'on',
|
||||||
@ -39,12 +39,30 @@ const headers = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
if (forceSSL) {
|
if (forceSSL) {
|
||||||
headers.push({
|
defaultHeaders.push({
|
||||||
key: 'Strict-Transport-Security',
|
key: 'Strict-Transport-Security',
|
||||||
value: 'max-age=63072000; includeSubDomains; preload',
|
value: 'max-age=63072000; includeSubDomains; preload',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const trackerHeaders = [
|
||||||
|
{
|
||||||
|
key: 'Access-Control-Allow-Origin',
|
||||||
|
value: '*',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const headers = [
|
||||||
|
{
|
||||||
|
source: '/:path*',
|
||||||
|
headers: defaultHeaders,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: '/script.js',
|
||||||
|
headers: trackerHeaders,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
const rewrites = [];
|
const rewrites = [];
|
||||||
|
|
||||||
if (collectApiEndpoint) {
|
if (collectApiEndpoint) {
|
||||||
@ -54,19 +72,6 @@ if (collectApiEndpoint) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trackerScriptName) {
|
|
||||||
const names = trackerScriptName?.split(',').map(name => name.trim());
|
|
||||||
|
|
||||||
if (names) {
|
|
||||||
names.forEach(name => {
|
|
||||||
rewrites.push({
|
|
||||||
source: `/${name.replace(/^\/+/, '')}`,
|
|
||||||
destination: '/tracker.js',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const redirects = [
|
const redirects = [
|
||||||
{
|
{
|
||||||
source: '/settings',
|
source: '/settings',
|
||||||
@ -85,6 +90,27 @@ const redirects = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Adding rewrites + headers for all alternative tracker script names.
|
||||||
|
if (trackerScriptName) {
|
||||||
|
const names = trackerScriptName?.split(',').map(name => name.trim());
|
||||||
|
|
||||||
|
if (names) {
|
||||||
|
names.forEach(name => {
|
||||||
|
const normalizedSource = `/${name.replace(/^\/+/, '')}`;
|
||||||
|
|
||||||
|
rewrites.push({
|
||||||
|
source: normalizedSource,
|
||||||
|
destination: '/script.js',
|
||||||
|
});
|
||||||
|
|
||||||
|
headers.push({
|
||||||
|
source: normalizedSource,
|
||||||
|
headers: trackerHeaders,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (cloudMode && cloudUrl) {
|
if (cloudMode && cloudUrl) {
|
||||||
redirects.push({
|
redirects.push({
|
||||||
source: '/settings/:path*',
|
source: '/settings/:path*',
|
||||||
@ -153,12 +179,7 @@ const config = {
|
|||||||
return config;
|
return config;
|
||||||
},
|
},
|
||||||
async headers() {
|
async headers() {
|
||||||
return [
|
return headers;
|
||||||
{
|
|
||||||
source: '/:path*',
|
|
||||||
headers,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
},
|
},
|
||||||
async rewrites() {
|
async rewrites() {
|
||||||
return [
|
return [
|
||||||
|
Loading…
Reference in New Issue
Block a user