-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lots of cleanup main issue now is snmp checker is refreshing
- Loading branch information
1 parent
ec006c7
commit 7f49d97
Showing
3 changed files
with
82 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
// src/middleware.ts | ||
import { NextResponse } from 'next/server'; | ||
import type { NextRequest } from 'next/server'; | ||
|
||
export function middleware(request: NextRequest) { | ||
const url = request.nextUrl.clone(); | ||
// Only apply to api routes | ||
if (request.nextUrl.pathname.startsWith('/api/')) { | ||
// Use the API key from environment | ||
const apiKey = process.env.API_KEY || ''; | ||
|
||
// Only apply to /api/* paths | ||
if (url.pathname.startsWith('/api/')) { | ||
// Clone the request headers | ||
const requestHeaders = new Headers(request.headers); | ||
|
||
const apiKey = process.env.API_KEY || ''; | ||
// Add the API key header | ||
requestHeaders.set('X-API-Key', apiKey); | ||
|
||
// Create a new request with added headers | ||
const modifiedRequest = new Request(url, { | ||
headers: { | ||
...request.headers, | ||
'X-API-Key': apiKey, | ||
// Return a new response with the API key header | ||
return NextResponse.next({ | ||
request: { | ||
headers: requestHeaders, | ||
}, | ||
}); | ||
|
||
return NextResponse.rewrite(url, { request: modifiedRequest }); | ||
} | ||
|
||
return NextResponse.next(); | ||
} | ||
|
||
export const config = { | ||
matcher: '/api/:path*', // Apply middleware only to /api/* routes | ||
matcher: '/api/:path*', | ||
}; |