fix(cloudfront): rewrite extensionless paths to index
- append /index.html for extensionless requests - document CloudFront Function behavior in README
This commit is contained in:
parent
8cd30da394
commit
a7b0752b55
2 changed files with 12 additions and 3 deletions
|
|
@ -11,6 +11,7 @@ It includes CloudFormation templates for provisioning all necessary components,
|
|||
- **Lambda (Go)**: Custom deployment logic executed within the pipeline
|
||||
- **ECR**: Container repository for Lambda packaging
|
||||
- **Secrets Manager**: Secure storage for deployment keys
|
||||
- **CloudFront Function**: Appends `/index.html` for extensionless paths (e.g. `/blog/2`, `/tags`)
|
||||
|
||||
All infrastructure is declaratively managed via CloudFormation templates under `infra/cfn/`.
|
||||
|
||||
|
|
|
|||
|
|
@ -20,10 +20,18 @@ Resources:
|
|||
function handler(event) {
|
||||
var request = event.request;
|
||||
var uri = request.uri;
|
||||
if (uri.endsWith("/")) {
|
||||
request.uri += "index.html";
|
||||
} else if (uri === "") {
|
||||
if (uri === "" || uri === "/") {
|
||||
request.uri = "/index.html";
|
||||
return request;
|
||||
}
|
||||
if (uri.endsWith("/")) {
|
||||
request.uri = uri + "index.html";
|
||||
return request;
|
||||
}
|
||||
var lastSlash = uri.lastIndexOf("/");
|
||||
var lastDot = uri.lastIndexOf(".");
|
||||
if (lastDot <= lastSlash) {
|
||||
request.uri = uri + "/index.html";
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue