@queue-it/fastly 2.0.3-beta.1 → 2.0.3-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { KnownUser
|
|
1
|
+
import { KnownUser } from "@queue-it/connector-javascript";
|
|
2
2
|
import { QueueITHelper } from "./helper";
|
|
3
3
|
import { FastlyHttpContextProvider, getHttpHandler } from "./contextProvider";
|
|
4
4
|
import {
|
|
@@ -8,6 +8,29 @@ import {
|
|
|
8
8
|
QueueItIntegrationEndpointProvider,
|
|
9
9
|
} from "./integrationConfigProvider";
|
|
10
10
|
|
|
11
|
+
function getParameterByName(url: string, name: string): string {
|
|
12
|
+
name = name.replace(/[\[\]]/g, '\\$&');
|
|
13
|
+
const regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)');
|
|
14
|
+
const results = regex.exec(url);
|
|
15
|
+
if (!results) return '';
|
|
16
|
+
if (!results[2]) return '';
|
|
17
|
+
return results[2].replace(/\+/g, ' ');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function removeQueueItToken(url: string): string {
|
|
21
|
+
const pattern = new RegExp("([?&])(" + KnownUser.QueueITTokenKey + "=[^&]*)", 'gi');
|
|
22
|
+
const match = pattern.exec(url);
|
|
23
|
+
if (match === null) return url;
|
|
24
|
+
url = url.replaceAll(match[0], '');
|
|
25
|
+
return url;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function addNoCacheHeaders(res: Response): void {
|
|
29
|
+
res.headers.set('Cache-Control', 'no-cache, no-store, must-revalidate, max-age=0');
|
|
30
|
+
res.headers.set('Pragma', 'no-cache');
|
|
31
|
+
res.headers.set('Expires', 'Fri, 01 Jan 1990 00:00:00 GMT');
|
|
32
|
+
}
|
|
33
|
+
|
|
11
34
|
const QUEUEIT_FAILED_HEADERNAME = "x-queueit-failed";
|
|
12
35
|
let httpProvider: FastlyHttpContextProvider | null = null;
|
|
13
36
|
|
|
@@ -34,11 +57,8 @@ export async function onQueueITRequest(
|
|
|
34
57
|
let integrationConfigJson = await getIntegrationConfig(conf, integrationProvider);
|
|
35
58
|
const requestUrl: string = conf.resolveWorkerRequestUrl(req.url);
|
|
36
59
|
|
|
37
|
-
const queueItToken =
|
|
38
|
-
|
|
39
|
-
KnownUser.QueueITTokenKey
|
|
40
|
-
);
|
|
41
|
-
const requestUrlWithoutToken: string = Utils.removeQueueItToken(requestUrl);
|
|
60
|
+
const queueItToken = getParameterByName(requestUrl, KnownUser.QueueITTokenKey);
|
|
61
|
+
const requestUrlWithoutToken: string = removeQueueItToken(requestUrl);
|
|
42
62
|
|
|
43
63
|
// The requestUrlWithoutToken is used to match Triggers and as the Target url (where to return the users to).
|
|
44
64
|
// It is therefor important that this is exactly the url of the users browsers. So, if your webserver is
|
|
@@ -71,7 +91,7 @@ export async function onQueueITRequest(
|
|
|
71
91
|
validationResult.getAjaxRedirectUrl()
|
|
72
92
|
)
|
|
73
93
|
);
|
|
74
|
-
|
|
94
|
+
addNoCacheHeaders(response);
|
|
75
95
|
return response;
|
|
76
96
|
} else {
|
|
77
97
|
let response = new Response(null, {
|
|
@@ -83,7 +103,7 @@ export async function onQueueITRequest(
|
|
|
83
103
|
"Location",
|
|
84
104
|
QueueITHelper.addKUPlatformVersion(validationResult.redirectUrl)
|
|
85
105
|
);
|
|
86
|
-
|
|
106
|
+
addNoCacheHeaders(response);
|
|
87
107
|
return response;
|
|
88
108
|
}
|
|
89
109
|
} else if (validationResultPair.first != null) {
|
|
@@ -100,7 +120,7 @@ export async function onQueueITRequest(
|
|
|
100
120
|
headers: httpProvider!.getHttpResponse().getHeaders(),
|
|
101
121
|
});
|
|
102
122
|
response.headers.set("Location", requestUrlWithoutToken);
|
|
103
|
-
|
|
123
|
+
addNoCacheHeaders(response);
|
|
104
124
|
return response;
|
|
105
125
|
} else {
|
|
106
126
|
// lets caller decide the next step, or just serve the request normally
|