|
1 | 1 | const util = require("./util"); |
2 | 2 |
|
3 | | -// this function exists in the npm lib: prerendercloud |
4 | | -// but must also exist here since we use it in our 404->/index.html |
5 | | -// functionality when the file has no extension or .html extension |
6 | | -const pathIsBlacklisted = (blacklistedPaths, cloudfrontUri) => { |
7 | | - const paths = blacklistedPaths; |
8 | | - |
9 | | - if (paths && Array.isArray(paths)) { |
10 | | - return paths.some(path => { |
11 | | - if (path === cloudfrontUri) return true; |
12 | | - |
13 | | - if (path.endsWith("*")) { |
14 | | - const starIndex = path.indexOf("*"); |
15 | | - const pathSlice = path.slice(0, starIndex); |
16 | | - |
17 | | - if (cloudfrontUri.startsWith(pathSlice)) return true; |
18 | | - } |
19 | | - |
20 | | - return false; |
21 | | - }); |
22 | | - } |
23 | | - |
24 | | - return false; |
25 | | -}; |
26 | | - |
27 | 3 | module.exports = class ViewerRequestInterface { |
28 | 4 | static create(cachedOptions, cloudFrontRequest, callback) { |
29 | 5 | const vri = new this(cloudFrontRequest, callback); |
@@ -109,18 +85,20 @@ module.exports = class ViewerRequestInterface { |
109 | 85 | createNext(req, cachedOptions) { |
110 | 86 | return () => { |
111 | 87 | if ( |
112 | | - util.isHtml(this.cloudFrontRequest.uri) && |
113 | | - (!cachedOptions.blacklistPaths || |
114 | | - (cachedOptions.blacklistPaths && |
115 | | - !pathIsBlacklisted( |
116 | | - cachedOptions.blacklistPaths(req), |
117 | | - this.cloudFrontRequest.uri |
118 | | - ))) |
| 88 | + util.shouldRewriteToIndexHtml( |
| 89 | + req, |
| 90 | + cachedOptions, |
| 91 | + this.cloudFrontRequest.uri |
| 92 | + ) |
119 | 93 | ) { |
120 | | - console.log({ rewriteToIndexHtml: true }); |
| 94 | + console.log("ViewerRequestInterface.next", { |
| 95 | + rewriteToIndexHtml: true |
| 96 | + }); |
121 | 97 | this.cloudFrontRequest.uri = "/index.html"; |
122 | 98 | } else { |
123 | | - console.log({ rewriteToIndexHtml: false }); |
| 99 | + console.log("ViewerRequestInterface.next", { |
| 100 | + rewriteToIndexHtml: false |
| 101 | + }); |
124 | 102 | } |
125 | 103 |
|
126 | 104 | // the URI will not include query string when not pre-rendering |
|
0 commit comments