Use rewrites for tracker script name, closes #972

This commit is contained in:
Mike Cao 2022-02-18 20:00:21 -08:00
parent 1e4c3ebf3b
commit 460762bf3d
3 changed files with 18 additions and 10 deletions

View File

@ -2,9 +2,12 @@
FROM node:12.22-alpine AS build
ARG BASE_PATH
ARG DATABASE_TYPE
ARG TRACKER_SCRIPT_NAME
ENV BASE_PATH=$BASE_PATH
ENV DATABASE_URL "postgresql://umami:umami@db:5432/umami" \
DATABASE_TYPE=$DATABASE_TYPE
ENV DATABASE_URL "postgresql://umami:umami@db:5432/umami"
ENV DATABASE_TYPE=$DATABASE_TYPE
ENV TRACKER_SCRIPT_NAME=$TRACKER_SCRIPT_NAME
WORKDIR /build
RUN yarn config set --home enableTelemetry 0

View File

@ -1,14 +1,16 @@
require('dotenv').config();
const pkg = require('./package.json');
const { BASE_PATH, FORCE_SSL, DISABLE_LOGIN, TRACKER_SCRIPT_NAME } = process.env;
module.exports = {
env: {
VERSION: pkg.version,
FORCE_SSL: !!process.env.FORCE_SSL,
DISABLE_LOGIN: !!process.env.DISABLE_LOGIN,
TRACKER_SCRIPT_NAME: process.env.TRACKER_SCRIPT_NAME,
FORCE_SSL: Boolean(FORCE_SSL),
DISABLE_LOGIN: Boolean(DISABLE_LOGIN),
TRACKER_SCRIPT_NAME,
},
basePath: process.env.BASE_PATH,
basePath: BASE_PATH,
eslint: {
ignoreDuringBuilds: true,
},
@ -21,10 +23,15 @@ module.exports = {
return config;
},
async rewrites() {
return TRACKER_SCRIPT_NAME
? [{ source: `/${TRACKER_SCRIPT_NAME}.js`, destination: '/umami.js' }]
: [];
},
async headers() {
return [
{
source: '/umami.js',
source: `/${TRACKER_SCRIPT_NAME || 'umami'}.js`,
headers: [
{
key: 'Cache-Control',

View File

@ -3,12 +3,10 @@ import buble from '@rollup/plugin-buble';
import resolve from '@rollup/plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
const scriptName = process.env.TRACKER_SCRIPT_NAME || 'umami';
export default {
input: 'tracker/index.js',
output: {
file: `public/${scriptName}.js`,
file: 'public/umami.js',
format: 'iife',
},
plugins: [resolve(), buble({ objectAssign: true }), terser({ compress: { evaluate: false } })],