-
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.
api keys between web and cloud api starting to work
- Loading branch information
1 parent
7e90364
commit ec006c7
Showing
6 changed files
with
73 additions
and
25 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 |
---|---|---|
|
@@ -57,4 +57,5 @@ type APIServer struct { | |
snmpManager snmp.SNMPManager | ||
db db.Service | ||
knownPollers []string | ||
apiKey string | ||
} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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/* paths | ||
if (url.pathname.startsWith('/api/')) { | ||
|
||
const apiKey = process.env.API_KEY || ''; | ||
|
||
// Create a new request with added headers | ||
const modifiedRequest = new Request(url, { | ||
headers: { | ||
...request.headers, | ||
'X-API-Key': apiKey, | ||
}, | ||
}); | ||
|
||
return NextResponse.rewrite(url, { request: modifiedRequest }); | ||
} | ||
|
||
return NextResponse.next(); | ||
} | ||
|
||
export const config = { | ||
matcher: '/api/:path*', // Apply middleware only to /api/* routes | ||
}; |