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
|
|
|
|
2026-03-02 10:36:17 -08: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;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-20 15:40:58 -04:00
|
|
|
const accountResponse = middlewares.account(req);
|
|
|
|
|
if (accountResponse) {
|
|
|
|
|
return accountResponse;
|
2022-09-16 16:55:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const res = NextResponse.next();
|
2024-05-07 15:52:20 +04:00
|
|
|
|
2026-01-05 13:32:05 +01:00
|
|
|
middlewares.appProfile(req, res);
|
2024-05-07 15:52:20 +04:00
|
|
|
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);
|
2026-03-01 18:00:00 -08:00
|
|
|
middlewares.poorReputationTokens(req, res);
|
2024-05-07 15:52:20 +04:00
|
|
|
|
|
|
|
|
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
|
|
|
};
|