Skip to content

Commit

Permalink
replace ci prefix only at rewriting part
Browse files Browse the repository at this point in the history
Signed-off-by: Tianle Huang <[email protected]>
  • Loading branch information
tianleh committed Mar 1, 2022
1 parent 9cb1ffb commit b6a6c0f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions deployment/lambdas/cf-url-rewriter/cf-url-rewriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { httpsGet } from './https-get';

export async function handler(event: CloudFrontRequestEvent, context: Context, callback: CloudFrontRequestCallback) {
const request = event.Records[0].cf.request;
// Incoming URLs from ci.opensearch.org will have a '/ci/123/' prefix, remove the prefix path from requests into S3.
request.uri = request.uri.replace(/^\/ci\/...\//, '\/');

if (request.uri.includes("/latest/")) {

Expand All @@ -24,6 +22,8 @@ export async function handler(event: CloudFrontRequestEvent, context: Context, c
}

} else {
// Incoming URLs from ci.opensearch.org will have a '/ci/123/' prefix, remove the prefix path from requests into S3.
request.uri = request.uri.replace(/^\/ci\/...\//, '\/');
callback(null, request);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ test('handler with latest url and with ci keyword and valid latest field', async

await handler(event, context, callback);

expect(httpsGet).toBeCalledWith('https://test.cloudfront.net/bundle-build-dashboards/1.2.0/index.json');
expect(httpsGet).toBeCalledWith('https://test.cloudfront.net/ci/dbc/bundle-build-dashboards/1.2.0/index.json');

expect(callback).toHaveBeenCalledWith(
null,
{
"headers": {
"cache-control": [{ "key": "Cache-Control", "value": "max-age=3600" }],
"location": [{ "key": "Location", "value": "/bundle-build-dashboards/1.2.0/123/linux/x64/" }]
"location": [{ "key": "Location", "value": "/ci/dbc/bundle-build-dashboards/1.2.0/123/linux/x64/" }]
},
"status": "302",
"statusDescription": "Moved temporarily"
Expand Down

0 comments on commit b6a6c0f

Please sign in to comment.