Skip to content

Commit b0ee537

Browse files
committed
feat: update GCS proxy endpoint to serve static files instead of reports
1 parent 36d542b commit b0ee537

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

src/controllers/cdnController.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@ function getMimeType(filePath) {
3636

3737
/**
3838
* Proxy endpoint to serve files from private GCS bucket
39-
* GET /v1/reports/*
39+
* GET /v1/static/*
4040
*
41-
* This serves as a proxy for files stored in gs://httparchive/reports/
42-
* The request path after /v1/reports/ maps directly to the GCS object path
41+
* This serves as a proxy for files stored in gs://httparchive/
42+
* The request path after /v1/static/ maps directly to the GCS object path
4343
*/
4444
export const proxyReportsFile = async (req, res, filePath) => {
4545
try {
4646
const BUCKET_NAME = process.env.GCS_BUCKET_NAME || 'httparchive';
47-
const BASE_PATH = process.env.GCS_REPORTS_PATH || 'reports';
4847

4948
// Validate file path to prevent directory traversal
5049
if (filePath.includes('..') || filePath.includes('//')) {
@@ -53,11 +52,8 @@ export const proxyReportsFile = async (req, res, filePath) => {
5352
return;
5453
}
5554

56-
// Remove leading slash if present
57-
const cleanPath = filePath.startsWith('/') ? filePath.slice(1) : filePath;
58-
59-
// Construct the full GCS object path
60-
const objectPath = `${BASE_PATH}/${cleanPath}`;
55+
// Remove leading slash if present - use path directly without base path prefix
56+
const objectPath = filePath.startsWith('/') ? filePath.slice(1) : filePath;
6157

6258
// Get the file from GCS
6359
const bucket = storage.bucket(BUCKET_NAME);

src/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ const getController = async (name) => {
4747
case 'cdn':
4848
controllers[name] = await import('./controllers/cdnController.js');
4949
break;
50-
default:
51-
throw new Error(`Unknown controller: ${name}`);
5250
}
5351
}
5452
return controllers[name];
@@ -174,9 +172,9 @@ const handleRequest = async (req, res) => {
174172
const { resetCache } = await import('./utils/controllerHelpers.js');
175173
const result = resetCache();
176174
sendJSONResponse(res, result);
177-
} else if (pathname.startsWith('/v1/reports/') && req.method === 'GET') {
175+
} else if (pathname.startsWith('/v1/static/') && req.method === 'GET') {
178176
// GCS proxy endpoint for reports files
179-
const filePath = pathname.replace('/v1/reports/', '');
177+
const filePath = pathname.replace('/v1/static/', '');
180178
if (!filePath) {
181179
res.statusCode = 400;
182180
res.end(JSON.stringify({ error: 'File path required' }));

0 commit comments

Comments
 (0)