fix: fix web build

This commit is contained in:
2024-12-30 06:52:15 +08:00
parent a4c549e7c3
commit 4c6cc1116b
2 changed files with 30 additions and 25 deletions

View File

@@ -6,7 +6,7 @@ import {
noseconeConfig,
noseconeMiddleware,
} from '@konobangu/security/middleware';
import { NextResponse } from 'next/server';
import { type NextRequest, NextResponse } from 'next/server';
export const config = {
// matcher tells Next.js which routes to run the middleware on. This runs the
@@ -16,26 +16,32 @@ export const config = {
const securityHeaders = noseconeMiddleware(noseconeConfig);
export default authMiddleware(async (_auth, request) => {
if (!env.ARCJET_KEY) {
return securityHeaders();
}
export const middleware = async (request: NextRequest) => {
const beforeMiddleware = async (request: NextRequest) => {
if (!env.ARCJET_KEY) {
return securityHeaders();
}
try {
await secure(
[
// See https://docs.arcjet.com/bot-protection/identifying-bots
'CATEGORY:SEARCH_ENGINE', // Allow search engines
'CATEGORY:PREVIEW', // Allow preview links to show OG images
'CATEGORY:MONITOR', // Allow uptime monitoring services
],
request
);
try {
await secure(
[
// See https://docs.arcjet.com/bot-protection/identifying-bots
'CATEGORY:SEARCH_ENGINE', // Allow search engines
'CATEGORY:PREVIEW', // Allow preview links to show OG images
'CATEGORY:MONITOR', // Allow uptime monitoring services
],
request
);
return securityHeaders();
} catch (error) {
const message = parseError(error);
return securityHeaders();
} catch (error) {
const message = parseError(error);
return NextResponse.json({ error: message }, { status: 403 });
}
});
return NextResponse.json({ error: message }, { status: 403 });
}
};
const response = await beforeMiddleware(request);
return authMiddleware(response as any);
};