WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 4cab4e9

Browse files
committed
Upgraded react. Fixed docker build.
1 parent 5c324fc commit 4cab4e9

File tree

5 files changed

+169
-172
lines changed

5 files changed

+169
-172
lines changed

Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ FROM node:22-alpine AS builder
1212
WORKDIR /app
1313
COPY --from=deps /app/node_modules ./node_modules
1414
COPY . .
15+
COPY docker/middleware.ts ./src
1516

1617
ARG DATABASE_TYPE
1718
ARG BASE_PATH
@@ -55,9 +56,6 @@ COPY --from=builder /app/scripts ./scripts
5556
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
5657
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
5758

58-
# Custom routes
59-
RUN mv ./.next/routes-manifest.json ./.next/routes-manifest-orig.json
60-
6159
USER nextjs
6260

6361
EXPOSE 3000

docker/middleware.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { type NextRequest, NextResponse } from 'next/server';
2+
3+
export const config = {
4+
matcher: '/:path*',
5+
};
6+
7+
const TRACKER_PATH = '/script.js';
8+
const COLLECT_PATH = '/api/send';
9+
const LOGIN_PATH = '/login';
10+
11+
const apiHeaders = {
12+
'Access-Control-Allow-Origin': '*',
13+
'Access-Control-Allow-Headers': '*',
14+
'Access-Control-Allow-Methods': 'GET, DELETE, POST, PUT',
15+
'Access-Control-Max-Age': process.env.CORS_MAX_AGE || '86400',
16+
'Cache-Control': 'no-cache',
17+
};
18+
19+
const trackerHeaders = {
20+
'Access-Control-Allow-Origin': '*',
21+
'Cache-Control': 'public, max-age=86400, must-revalidate',
22+
};
23+
24+
function customCollectEndpoint(request: NextRequest) {
25+
const collectEndpoint = process.env.COLLECT_API_ENDPOINT;
26+
27+
if (collectEndpoint) {
28+
const url = request.nextUrl.clone();
29+
30+
if (url.pathname.endsWith(collectEndpoint)) {
31+
url.pathname = COLLECT_PATH;
32+
return NextResponse.rewrite(url, { headers: apiHeaders });
33+
}
34+
}
35+
}
36+
37+
function customScriptName(request: NextRequest) {
38+
const scriptName = process.env.TRACKER_SCRIPT_NAME;
39+
40+
if (scriptName) {
41+
const url = request.nextUrl.clone();
42+
const names = scriptName.split(',').map(name => name.trim().replace(/^\/+/, ''));
43+
44+
if (names.find(name => url.pathname.endsWith(name))) {
45+
url.pathname = TRACKER_PATH;
46+
return NextResponse.rewrite(url, { headers: trackerHeaders });
47+
}
48+
}
49+
}
50+
51+
function customScriptUrl(request: NextRequest) {
52+
const scriptUrl = process.env.TRACKER_SCRIPT_URL;
53+
54+
if (scriptUrl && request.nextUrl.pathname.endsWith(TRACKER_PATH)) {
55+
return NextResponse.rewrite(scriptUrl, { headers: trackerHeaders });
56+
}
57+
}
58+
59+
function disableLogin(request: NextRequest) {
60+
const loginDisabled = process.env.DISABLE_LOGIN;
61+
62+
if (loginDisabled && request.nextUrl.pathname.endsWith(LOGIN_PATH)) {
63+
return new NextResponse('Access denied', { status: 403 });
64+
}
65+
}
66+
67+
export default function middleware(req: NextRequest) {
68+
const fns = [customCollectEndpoint, customScriptName, customScriptUrl, disableLogin];
69+
70+
for (const fn of fns) {
71+
const res = fn(req);
72+
if (res) {
73+
return res;
74+
}
75+
}
76+
77+
return NextResponse.next();
78+
}

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "umami",
3-
"version": "2.20.0",
3+
"version": "2.20.1",
44
"description": "A modern, privacy-focused alternative to Google Analytics.",
55
"author": "Umami Software, Inc. <[email protected]>",
66
"license": "MIT",
@@ -15,7 +15,7 @@
1515
"build": "npm-run-all check-env build-db check-db build-tracker build-geo build-app",
1616
"start": "next start",
1717
"build-docker": "npm-run-all build-db build-tracker build-geo build-app",
18-
"start-docker": "npm-run-all check-db update-tracker set-routes-manifest start-server",
18+
"start-docker": "npm-run-all check-db update-tracker start-server",
1919
"start-env": "node scripts/start-env.js",
2020
"start-server": "node server.js",
2121
"build-app": "next build",
@@ -26,7 +26,6 @@
2626
"build-geo": "node scripts/build-geo.js",
2727
"build-db-schema": "prisma db pull",
2828
"build-db-client": "prisma generate",
29-
"set-routes-manifest": "node scripts/set-routes-manifest.js",
3029
"update-tracker": "node scripts/update-tracker.js",
3130
"update-db": "prisma migrate deploy",
3231
"check-db": "node scripts/check-db.js",
@@ -110,9 +109,9 @@
110109
"papaparse": "^5.5.3",
111110
"prisma": "6.7.0",
112111
"pure-rand": "^6.1.0",
113-
"react": "^19.0.0",
112+
"react": "^19.2.1",
114113
"react-basics": "^0.126.0",
115-
"react-dom": "^19.0.0",
114+
"react-dom": "^19.2.1",
116115
"react-error-boundary": "^4.0.4",
117116
"react-intl": "^6.5.5",
118117
"react-simple-maps": "^2.3.0",

0 commit comments

Comments
 (0)