Skip to content

Commit b33313b

Browse files
committed
feat: update API routes and MIME type handling for static files
1 parent 77880e5 commit b33313b

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

src/__tests__/routes.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ describe('API Routes', () => {
447447
});
448448

449449
it('should infer MIME type from file extension when not in metadata', async () => {
450-
const fileContent = '<html></html>';
450+
const fileContent = '{"test": true}';
451451
const readable = Readable.from([fileContent]);
452452

453453
mockFileExists.mockResolvedValue([true]);
@@ -458,10 +458,10 @@ describe('API Routes', () => {
458458
mockCreateReadStream.mockReturnValue(readable);
459459

460460
const res = await request(app)
461-
.get('/v1/static/reports/page.html')
461+
.get('/v1/static/reports/data.json')
462462
.expect(200);
463463

464-
expect(res.headers['content-type']).toContain('text/html');
464+
expect(res.headers['content-type']).toContain('application/json');
465465
});
466466

467467
it('should handle CORS preflight requests', async () => {

src/controllers/cdnController.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,11 @@ const storage = new Storage();
66
// MIME type mapping for common file extensions
77
const MIME_TYPES = {
88
'.json': 'application/json',
9-
'.html': 'text/html',
10-
'.css': 'text/css',
119
'.js': 'application/javascript',
1210
'.png': 'image/png',
13-
'.jpg': 'image/jpeg',
14-
'.jpeg': 'image/jpeg',
15-
'.gif': 'image/gif',
1611
'.svg': 'image/svg+xml',
17-
'.webp': 'image/webp',
18-
'.ico': 'image/x-icon',
19-
'.txt': 'text/plain',
2012
'.csv': 'text/csv',
21-
'.xml': 'application/xml',
22-
'.pdf': 'application/pdf',
23-
'.woff': 'font/woff',
24-
'.woff2': 'font/woff2',
25-
'.ttf': 'font/ttf',
26-
'.eot': 'application/vnd.ms-fontobject'
13+
'.pdf': 'application/pdf'
2714
};
2815

2916
/**

terraform/dev/main.tf

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ paths:
112112
responses:
113113
200:
114114
description: String
115-
/v1/static/{filePath}:
115+
/v1/static/{filePath=**}:
116116
get:
117117
summary: static
118118
operationId: getStaticFile
@@ -123,9 +123,7 @@ paths:
123123
type: string
124124
responses:
125125
200:
126-
description: String
127-
schema:
128-
type: string
126+
description: File content
129127
EOF
130128
)
131129
}

terraform/prod/main.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,25 @@ paths:
105105
responses:
106106
200:
107107
description: String
108+
/v1/versions:
109+
get:
110+
summary: versions
111+
operationId: getVersions
112+
responses:
113+
200:
114+
description: String
115+
/v1/static/{filePath=**}:
116+
get:
117+
summary: static
118+
operationId: getStaticFile
119+
parameters:
120+
- name: filePath
121+
in: path
122+
required: true
123+
type: string
124+
responses:
125+
200:
126+
description: File content
108127
EOF
109128
)
110129
}

0 commit comments

Comments
 (0)