@@ -307,7 +307,6 @@ export class CdnStack {
307
307
code : lambda . Code . fromInline ( `
308
308
const config = {
309
309
suffix: '.html',
310
- appendToDirs: 'index.html',
311
310
}
312
311
313
312
const regexSuffixless = /\\/[^/.]+$/
@@ -317,18 +316,24 @@ export class CdnStack {
317
316
const request = event.Records[0].cf.request;
318
317
let uri = request.uri;
319
318
320
- // Remove /docs prefix
321
- if (uri.startsWith('/docs')) {
322
- uri = uri.replace('/docs', '') || '/';
319
+ if (uri === '/docs' || uri === '/docs/') {
320
+ uri = '/index.html'
321
+ callback(null, request)
322
+ return
323
323
}
324
324
325
325
// Append ".html" to origin request
326
326
if (uri.match(regexSuffixless)) {
327
- uri = uri + config.suffix;
327
+ request.uri = uri + suffix
328
+ callback(null, request)
329
+ return
328
330
}
329
- // Append "index.html" to origin request
330
- else if (uri.match(regexTrailingSlash)) {
331
- uri = uri + config.appendToDirs;
331
+
332
+ // Remove trailing slash and append ".html" to origin request
333
+ if (uri.match(regexTrailingSlash)) {
334
+ request.uri = uri.slice(0, -1) + '.html'
335
+ callback(null, request)
336
+ return
332
337
}
333
338
334
339
request.uri = uri;
@@ -343,6 +348,28 @@ export class CdnStack {
343
348
functionName : docsOriginRequestFunction . functionName ,
344
349
} )
345
350
351
+ // const docsOriginResponseFunction = new lambda.Function(scope, 'DocsOriginResponseFunction', {
352
+ // functionName: `${this.props.slug}-${this.props.appEnv}-docs-origin-response-function`,
353
+ // description: 'Custom origin response function for the docs',
354
+ // runtime: lambda.Runtime.NODEJS_20_X,
355
+ // handler: 'index.handler',
356
+ // code: lambda.Code.fromInline(`
357
+ // exports.handler = (event, context, callback) => {
358
+ // const response = event.Records[0].cf.response;
359
+ // response.headers['x-custom-header'] = {
360
+ // value: 'custom-value',
361
+ // };
362
+ // callback(null, response);
363
+ // };
364
+ // `),
365
+ // })
366
+
367
+ // new lambda.CfnPermission(scope, 'DocsOriginResponseFunctionPermission', {
368
+ // action: 'lambda:InvokeFunction',
369
+ // principal: 'edgelambda.amazonaws.com',
370
+ // functionName: docsOriginResponseFunction.functionName,
371
+ // })
372
+
346
373
const commonBehavior : cloudfront . BehaviorOptions = {
347
374
origin,
348
375
compress : true ,
@@ -356,6 +383,10 @@ export class CdnStack {
356
383
functionVersion : docsOriginRequestFunction . currentVersion ,
357
384
eventType : cloudfront . LambdaEdgeEventType . ORIGIN_REQUEST ,
358
385
} ,
386
+ // {
387
+ // functionVersion: docsOriginResponseFunction.currentVersion,
388
+ // eventType: cloudfront.LambdaEdgeEventType.ORIGIN_RESPONSE,
389
+ // },
359
390
] ,
360
391
// functionAssociations: [
361
392
// {
0 commit comments