Spaces:
Configuration error
Configuration error
Download docker/middleware.js from SreejithSHR/umami: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/SreejithSHR/umami/resolve/main/docker/middleware.js
- Command line
-
hf download hf://spaces/SreejithSHR/umami/docker/middleware.js
-
curl -L -o middleware.js https://huggingface.co/spaces/SreejithSHR/umami/resolve/main/docker/middleware.js
1.05 kB
| 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; | |
| const names = scriptName.split(',').map(name => name.trim().replace(/^\/+/, '')); | |
| if (names.find(name => pathname.endsWith(name))) { | |
| 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(); | |
| } | |