-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcloudfront-function.js
More file actions
41 lines (34 loc) · 1.04 KB
/
cloudfront-function.js
File metadata and controls
41 lines (34 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function handler(event) {
var request = event.request;
var uri = request.uri;
// 정적 파일들은 그대로 통과
if (uri.includes('.')) {
return request;
}
// 루트 경로는 index.html로
if (uri === '/') {
request.uri = '/index.html';
return request;
}
// 다른 경로들은 해당하는 HTML 파일로 변환
// /canary-deploy -> /canary-deploy.html
// /dark-release -> /dark-release.html
if (uri.startsWith('/')) {
var path = uri.substring(1); // 첫 번째 '/' 제거
// 쿼리 파라미터가 있는 경우 제거
if (path.includes('?')) {
path = path.split('?')[0];
}
// 경로 끝의 슬래시 제거
if (path.endsWith('/')) {
path = path.slice(0, -1);
}
// HTML 파일로 변환
if (path) {
request.uri = '/' + path + '.html';
} else {
request.uri = '/index.html';
}
}
return request;
}