mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* Add ENV variable allowing to choose default color schema Fixes #1868 * Update values.yaml.gotmpl --------- Co-authored-by: Yan Vaskov <[email protected]>
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import type { NextRequest } from 'next/server';
|
|
import { NextResponse } from 'next/server';
|
|
|
|
import generateCspPolicy from 'nextjs/csp/generateCspPolicy';
|
|
import * as middlewares from 'nextjs/middlewares/index';
|
|
|
|
const cspPolicy = generateCspPolicy();
|
|
|
|
export function middleware(req: NextRequest) {
|
|
const isPageRequest = req.headers.get('accept')?.includes('text/html');
|
|
const start = Date.now();
|
|
|
|
if (!isPageRequest) {
|
|
return;
|
|
}
|
|
|
|
const accountResponse = middlewares.account(req);
|
|
if (accountResponse) {
|
|
return accountResponse;
|
|
}
|
|
|
|
const res = NextResponse.next();
|
|
|
|
middlewares.colorTheme(req, res);
|
|
|
|
const end = Date.now();
|
|
|
|
res.headers.append('Content-Security-Policy', cspPolicy);
|
|
res.headers.append('Server-Timing', `middleware;dur=${ end - start }`);
|
|
res.headers.append('Docker-ID', process.env.HOSTNAME || '');
|
|
|
|
return res;
|
|
}
|
|
|
|
/**
|
|
* Configure which routes should pass through the Middleware.
|
|
*/
|
|
export const config = {
|
|
matcher: [ '/', '/:notunderscore((?!_next).+)' ],
|
|
// matcher: [
|
|
// '/((?!.*\\.|api\\/|node-api\\/).*)', // exclude all static + api + node-api routes
|
|
// ],
|
|
};
|