feat(auth): add api key authentication
Implement API key authentication by introducing a new auth module. Update configuration and .env.example to support API key setup, and add authorization checks in the server endpoints.
This commit is contained in:
@@ -8,6 +8,7 @@ import { listModels, sendChat, sendChatStream } from './chatwrapper';
|
||||
import { mapRequest, mapResponse, mapStreamChunk } from './mapper.js';
|
||||
import { RequestBody, GeminiResponse, GeminiStreamChunk, Part } from './types';
|
||||
import { config } from './config';
|
||||
import { isAuthorized } from './auth';
|
||||
|
||||
// ==================================================================
|
||||
// Server Configuration
|
||||
@@ -97,6 +98,10 @@ http
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isAuthorized(req, res)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Route for listing available models.
|
||||
if (pathname === '/v1/models' || pathname === '/models') {
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
|
||||
Reference in New Issue
Block a user