Added TRACKER_SCRIPT_URL env var.

This commit is contained in:
Mike Cao 2024-10-29 16:39:51 -07:00
parent 9758b5523a
commit 1225473c20
3 changed files with 14 additions and 8 deletions

View File

@ -3,6 +3,8 @@ require('dotenv').config();
const path = require('path'); const path = require('path');
const pkg = require('./package.json'); const pkg = require('./package.json');
const TRACKER_SCRIPT = '/script.js';
const basePath = process.env.BASE_PATH; const basePath = process.env.BASE_PATH;
const collectApiEndpoint = process.env.COLLECT_API_ENDPOINT; const collectApiEndpoint = process.env.COLLECT_API_ENDPOINT;
const cloudMode = process.env.CLOUD_MODE; const cloudMode = process.env.CLOUD_MODE;
@ -14,6 +16,7 @@ const forceSSL = process.env.FORCE_SSL;
const frameAncestors = process.env.ALLOWED_FRAME_URLS; const frameAncestors = process.env.ALLOWED_FRAME_URLS;
const privateMode = process.env.PRIVATE_MODE; const privateMode = process.env.PRIVATE_MODE;
const trackerScriptName = process.env.TRACKER_SCRIPT_NAME; const trackerScriptName = process.env.TRACKER_SCRIPT_NAME;
const trackerScriptURL = process.env.TRACKER_SCRIPT_URL;
const contentSecurityPolicy = [ const contentSecurityPolicy = [
`default-src 'self'`, `default-src 'self'`,
@ -58,13 +61,20 @@ const headers = [
headers: defaultHeaders, headers: defaultHeaders,
}, },
{ {
source: '/script.js', source: TRACKER_SCRIPT,
headers: trackerHeaders, headers: trackerHeaders,
}, },
]; ];
const rewrites = []; const rewrites = [];
if (trackerScriptURL) {
rewrites.push({
source: TRACKER_SCRIPT,
destination: trackerScriptURL,
});
}
if (collectApiEndpoint) { if (collectApiEndpoint) {
rewrites.push({ rewrites.push({
source: collectApiEndpoint, source: collectApiEndpoint,
@ -100,7 +110,7 @@ if (trackerScriptName) {
rewrites.push({ rewrites.push({
source: normalizedSource, source: normalizedSource,
destination: '/script.js', destination: TRACKER_SCRIPT,
}); });
headers.push({ headers.push({
@ -184,10 +194,6 @@ const config = {
async rewrites() { async rewrites() {
return [ return [
...rewrites, ...rewrites,
{
source: '/script.js',
destination: 'https://tracker-script.umami.dev/',
},
{ {
source: '/telemetry.js', source: '/telemetry.js',
destination: '/api/scripts/telemetry', destination: '/api/scripts/telemetry',

View File

@ -1,6 +1,6 @@
{ {
"name": "umami", "name": "umami",
"version": "2.13.2", "version": "2.14.0",
"description": "A simple, fast, privacy-focused alternative to Google Analytics.", "description": "A simple, fast, privacy-focused alternative to Google Analytics.",
"author": "Umami Software, Inc. <hello@umami.is>", "author": "Umami Software, Inc. <hello@umami.is>",
"license": "MIT", "license": "MIT",

View File

@ -5,7 +5,7 @@ import { terser } from 'rollup-plugin-terser';
export default { export default {
input: 'src/tracker/index.js', input: 'src/tracker/index.js',
output: { output: {
file: 'public/tracker.js', file: 'public/script.js',
format: 'iife', format: 'iife',
}, },
plugins: [ plugins: [