mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
Added middleware for docker.
This commit is contained in:
parent
3eabe9b958
commit
ac8d8bbd1e
@ -12,6 +12,7 @@ RUN yarn install --frozen-lockfile
|
|||||||
FROM node:18-alpine AS builder
|
FROM node:18-alpine AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=deps /app/node_modules ./node_modules
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
|
COPY docker/middleware.js .
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
ARG DATABASE_TYPE
|
ARG DATABASE_TYPE
|
||||||
|
46
docker/middleware.js
Normal file
46
docker/middleware.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import { NextResponse } from 'next/server';
|
||||||
|
|
||||||
|
export const config = {
|
||||||
|
matcher: '/:path*',
|
||||||
|
};
|
||||||
|
|
||||||
|
function customCollectEndpoint(req) {
|
||||||
|
const collectEndpoint = process.env.COLLECT_API_ENDPOINT;
|
||||||
|
|
||||||
|
if (collectEndpoint) {
|
||||||
|
const url = req.nextUrl.clone();
|
||||||
|
const { pathname } = url;
|
||||||
|
|
||||||
|
if (pathname.endsWith(collectEndpoint)) {
|
||||||
|
url.pathname = '/api/send';
|
||||||
|
return NextResponse.rewrite(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function customScriptName(req) {
|
||||||
|
const scriptName = process.env.TRACKER_SCRIPT_NAME;
|
||||||
|
|
||||||
|
if (scriptName) {
|
||||||
|
const url = req.nextUrl.clone();
|
||||||
|
const { pathname } = url;
|
||||||
|
|
||||||
|
if (pathname.endsWith(scriptName)) {
|
||||||
|
url.pathname = '/script.js';
|
||||||
|
return NextResponse.rewrite(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function middleware(req) {
|
||||||
|
const fns = [customCollectEndpoint, customScriptName];
|
||||||
|
|
||||||
|
for (const fn of fns) {
|
||||||
|
const res = fn(req);
|
||||||
|
if (res) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.next();
|
||||||
|
}
|
@ -44,6 +44,17 @@ if (process.env.COLLECT_API_ENDPOINT) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (process.env.TRACKER_SCRIPT_NAME) {
|
||||||
|
const match = process.env.TRACKER_SCRIPT_NAME?.match(/\/?(\w+)(\.js)?/);
|
||||||
|
|
||||||
|
if (match) {
|
||||||
|
rewrites.push({
|
||||||
|
source: `/${match[0]}.js`,
|
||||||
|
destination: '/script.js',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const redirects = [];
|
const redirects = [];
|
||||||
|
|
||||||
if (process.env.CLOUD_MODE) {
|
if (process.env.CLOUD_MODE) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "umami",
|
"name": "umami",
|
||||||
"version": "2.0.0",
|
"version": "2.1.0",
|
||||||
"description": "A simple, fast, privacy-focused alternative to Google Analytics.",
|
"description": "A simple, fast, privacy-focused alternative to Google Analytics.",
|
||||||
"author": "Mike Cao <mike@mikecao.com>",
|
"author": "Mike Cao <mike@mikecao.com>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user