mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 12:47:13 +01:00
Merge branch 'dev' into master
This commit is contained in:
commit
e32d2b988c
121 changed files with 15568 additions and 1757 deletions
|
|
@ -3,6 +3,8 @@ require('dotenv').config();
|
|||
const path = require('path');
|
||||
const pkg = require('./package.json');
|
||||
|
||||
const TRACKER_SCRIPT = '/script.js';
|
||||
|
||||
const basePath = process.env.BASE_PATH;
|
||||
const collectApiEndpoint = process.env.COLLECT_API_ENDPOINT;
|
||||
const cloudMode = process.env.CLOUD_MODE;
|
||||
|
|
@ -14,6 +16,7 @@ const forceSSL = process.env.FORCE_SSL;
|
|||
const frameAncestors = process.env.ALLOWED_FRAME_URLS;
|
||||
const privateMode = process.env.PRIVATE_MODE;
|
||||
const trackerScriptName = process.env.TRACKER_SCRIPT_NAME;
|
||||
const trackerScriptURL = process.env.TRACKER_SCRIPT_URL;
|
||||
|
||||
const contentSecurityPolicy = [
|
||||
`default-src 'self'`,
|
||||
|
|
@ -24,7 +27,7 @@ const contentSecurityPolicy = [
|
|||
`frame-ancestors 'self' ${frameAncestors}`,
|
||||
];
|
||||
|
||||
const headers = [
|
||||
const defaultHeaders = [
|
||||
{
|
||||
key: 'X-DNS-Prefetch-Control',
|
||||
value: 'on',
|
||||
|
|
@ -39,14 +42,39 @@ const headers = [
|
|||
];
|
||||
|
||||
if (forceSSL) {
|
||||
headers.push({
|
||||
defaultHeaders.push({
|
||||
key: 'Strict-Transport-Security',
|
||||
value: 'max-age=63072000; includeSubDomains; preload',
|
||||
});
|
||||
}
|
||||
|
||||
const trackerHeaders = [
|
||||
{
|
||||
key: 'Access-Control-Allow-Origin',
|
||||
value: '*',
|
||||
},
|
||||
];
|
||||
|
||||
const headers = [
|
||||
{
|
||||
source: '/:path*',
|
||||
headers: defaultHeaders,
|
||||
},
|
||||
{
|
||||
source: TRACKER_SCRIPT,
|
||||
headers: trackerHeaders,
|
||||
},
|
||||
];
|
||||
|
||||
const rewrites = [];
|
||||
|
||||
if (trackerScriptURL) {
|
||||
rewrites.push({
|
||||
source: TRACKER_SCRIPT,
|
||||
destination: trackerScriptURL,
|
||||
});
|
||||
}
|
||||
|
||||
if (collectApiEndpoint) {
|
||||
rewrites.push({
|
||||
source: collectApiEndpoint,
|
||||
|
|
@ -54,19 +82,6 @@ if (collectApiEndpoint) {
|
|||
});
|
||||
}
|
||||
|
||||
if (trackerScriptName) {
|
||||
const names = trackerScriptName?.split(',').map(name => name.trim());
|
||||
|
||||
if (names) {
|
||||
names.forEach(name => {
|
||||
rewrites.push({
|
||||
source: `/${name.replace(/^\/+/, '')}`,
|
||||
destination: '/script.js',
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const redirects = [
|
||||
{
|
||||
source: '/settings',
|
||||
|
|
@ -85,6 +100,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: TRACKER_SCRIPT,
|
||||
});
|
||||
|
||||
headers.push({
|
||||
source: normalizedSource,
|
||||
headers: trackerHeaders,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (cloudMode && cloudUrl) {
|
||||
redirects.push({
|
||||
source: '/settings/:path*',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue