Skip to content

Commit 2189b48

Browse files
committed
refactor: Update x-api-key
1 parent 40453fa commit 2189b48

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ These endpoints proxy requests to external LLM providers.
163163
#### RAG API Endpoints
164164

165165
##### Management Endpoints
166-
These endpoints are used to manage documents in the RAG system. **They are protected and require an `X-API-Key` header matching the `RAG_MANAGEMENT_API_KEY` defined in your `.env` file.**
166+
These endpoints are used to manage documents in the RAG system. **They are protected and require an `X-API-KEY` header matching the `RAG_MANAGEMENT_API_KEY` defined in your `.env` file.**
167167

168168
- **`POST /rag/manage/documents`**
169169
* Uploads a Markdown document.
@@ -210,7 +210,7 @@ The default port `8080` is used in these examples.
210210
211211
1. **Upload a document:**
212212
```bash
213-
curl -X POST -H "X-API-Key: your_secure_api_key_here" \
213+
curl -X POST -H "X-API-KEY: your_secure_api_key_here" \
214214
-F "documentId=my_test_doc_01" \
215215
-F "markdownFile=@/path/to/your/document.md" \
216216
http://localhost:8080/api/v1/rag/manage/documents
@@ -237,13 +237,13 @@ The default port `8080` is used in these examples.
237237
238238
3. **Get a document's content:**
239239
```bash
240-
curl -X GET -H "X-API-Key: your_secure_api_key_here" \
240+
curl -X GET -H "X-API-KEY: your_secure_api_key_here" \
241241
http://localhost:8080/api/v1/rag/manage/documents/my_test_doc_01
242242
```
243243

244244
4. **Delete a document:**
245245
```bash
246-
curl -X DELETE -H "X-API-Key: your_secure_api_key_here" \
246+
curl -X DELETE -H "X-API-KEY: your_secure_api_key_here" \
247247
http://localhost:8080/api/v1/rag/manage/documents/my_test_doc_01
248248
```
249249

src/middleware/__tests__/auth.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('API Key Authentication Middleware (apiKeyAuth)', () => {
3232
});
3333

3434
it('should call next() if API key is valid', () => {
35-
const req = mockRequest({ 'X-API-Key': 'test-api-key' }) as Request;
35+
const req = mockRequest({ 'X-API-KEY': 'test-api-key' }) as Request;
3636
const res = mockResponse() as Response;
3737

3838
apiKeyAuth(req, res, mockNextFunction);
@@ -43,7 +43,7 @@ describe('API Key Authentication Middleware (apiKeyAuth)', () => {
4343
});
4444

4545
it('should return 401 if API key is missing', () => {
46-
const req = mockRequest({}) as Request; // No X-API-Key header
46+
const req = mockRequest({}) as Request; // No X-API-KEY header
4747
const res = mockResponse() as Response;
4848

4949
apiKeyAuth(req, res, mockNextFunction);
@@ -54,7 +54,7 @@ describe('API Key Authentication Middleware (apiKeyAuth)', () => {
5454
});
5555

5656
it('should return 401 if API key is invalid', () => {
57-
const req = mockRequest({ 'X-API-Key': 'invalid-api-key' }) as Request;
57+
const req = mockRequest({ 'X-API-KEY': 'invalid-api-key' }) as Request;
5858
const res = mockResponse() as Response;
5959

6060
apiKeyAuth(req, res, mockNextFunction);
@@ -66,7 +66,7 @@ describe('API Key Authentication Middleware (apiKeyAuth)', () => {
6666

6767
it('should return 500 if RAG API key is not configured on the server (empty string)', () => {
6868
(config as any).ragApiKey = ''; // Simulate not configured (empty string)
69-
const req = mockRequest({ 'X-API-Key': 'any-key' }) as Request;
69+
const req = mockRequest({ 'X-API-KEY': 'any-key' }) as Request;
7070
const res = mockResponse() as Response;
7171

7272
apiKeyAuth(req, res, mockNextFunction);
@@ -80,7 +80,7 @@ describe('API Key Authentication Middleware (apiKeyAuth)', () => {
8080

8181
it('should return 500 if RAG API key is not configured on the server (undefined)', () => {
8282
(config as any).ragApiKey = undefined; // Simulate not configured (undefined)
83-
const req = mockRequest({ 'X-API-Key': 'any-key' }) as Request;
83+
const req = mockRequest({ 'X-API-KEY': 'any-key' }) as Request;
8484
const res = mockResponse() as Response;
8585

8686
apiKeyAuth(req, res, mockNextFunction);

src/middleware/auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { NextFunction, Request, Response } from 'express';
33
import { config } from '../config';
44

55
export const apiKeyAuth = (req: Request, res: Response, next: NextFunction) => {
6-
const apiKey = req.header('X-API-Key');
6+
const apiKey = req.header('X-API-KEY');
77

88
if (!config.ragApiKey || config.ragApiKey.trim() === '') {
99
console.error('RAG API Key not configured. Denying access.');
@@ -22,7 +22,7 @@ export const apiKeyAuth = (req: Request, res: Response, next: NextFunction) => {
2222
};
2323

2424
export const queryApiKeyAuth = (req: Request, res: Response, next: NextFunction) => {
25-
const apiKey = req.header('X-API-Key');
25+
const apiKey = req.header('X-API-KEY');
2626

2727
if (!config.ragQueryApiKey || config.ragQueryApiKey.trim() === '') {
2828
console.error('RAG Query API Key not configured. Denying access.');

src/swagger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const swaggerDocument = {
44
ApiKeyAuth: {
55
description: 'API Key for accessing protected endpoints.',
66
in: 'header',
7-
name: 'X-API-Key',
7+
name: 'X-API-KEY',
88
type: 'apiKey',
99
},
1010
},

0 commit comments

Comments
 (0)