Skip to content

Commit

Permalink
Fix edge-function
Browse files Browse the repository at this point in the history
  • Loading branch information
Tehnix committed Oct 15, 2023
1 parent 23cd79d commit a549072
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions posts/2023-10-16-the-stack-part-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -1601,7 +1601,7 @@ export class Stack extends cdk.Stack {
? [
{
functionVersion: rewriteUrl.currentVersion,
eventType: cloudfront.LambdaEdgeEventType.VIEWER_REQUEST,
eventType: cloudfront.LambdaEdgeEventType.ORIGIN_REQUEST,
},
]
: undefined,
Expand Down Expand Up @@ -1661,20 +1661,19 @@ export class Stack extends cdk.Stack {
And our Lambda@Edge function to rewrite urls is defined in `edge-functions/rewrite-urls.ts`:

```typescript
function handler(event) {
var request = event.request;
var uri = request.uri;
exports.handler = (event, _, callback) => {
let request = event.Records[0].cf.request;

// Check whether the URI is missing a file name.
if (uri.endsWith("/")) {
if (request.uri.endsWith("/")) {
request.uri += "index.html";
} else if (!uri.includes(".")) {
} else if (!request.uri.includes(".")) {
// Check whether the URI is missing a file extension.
request.uri += "/index.html";
}

return request;
}
return callback(null, request);
};
```


Expand Down

0 comments on commit a549072

Please sign in to comment.