Files
explore/proxy.ts
T

48 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-09-16 16:55:31 +03:00
import type { NextRequest } from 'next/server';
import { NextResponse } from 'next/server';
2025-07-03 15:07:00 +02:00
import * as csp from 'nextjs/csp/index';
2023-08-15 19:28:00 -04:00
import * as middlewares from 'nextjs/middlewares/index';
2022-09-16 16:55:31 +03:00
export async function proxy(req: NextRequest) {
2022-09-16 16:55:31 +03:00
const isPageRequest = req.headers.get('accept')?.includes('text/html');
2023-01-26 18:28:44 -06:00
const start = Date.now();
2022-09-16 16:55:31 +03:00
if (!isPageRequest) {
return;
}
const accountResponse = middlewares.account(req);
if (accountResponse) {
return accountResponse;
2022-09-16 16:55:31 +03:00
}
const res = NextResponse.next();
2026-01-05 13:32:05 +01:00
middlewares.appProfile(req, res);
middlewares.colorTheme(req, res);
2024-11-04 18:53:59 +01:00
middlewares.addressFormat(req, res);
2025-02-17 14:26:05 +01:00
middlewares.scamTokens(req, res);
middlewares.poorReputationTokens(req, res);
const end = Date.now();
2026-01-05 13:32:05 +01:00
const cspHeader = await csp.get(req);
2025-07-03 15:07:00 +02:00
res.headers.append('Content-Security-Policy', cspHeader);
2023-01-26 18:28:44 -06:00
res.headers.append('Server-Timing', `middleware;dur=${ end - start }`);
2023-04-27 17:40:48 -03:00
res.headers.append('Docker-ID', process.env.HOSTNAME || '');
2023-01-26 18:28:44 -06:00
2022-09-16 16:55:31 +03:00
return res;
}
/**
* Configure which routes should pass through the Middleware.
*/
export const config = {
2023-02-18 15:03:11 -05:00
matcher: [ '/', '/:notunderscore((?!_next).+)' ],
// matcher: [
// '/((?!.*\\.|api\\/|node-api\\/).*)', // exclude all static + api + node-api routes
// ],
2022-09-16 16:55:31 +03:00
};