forked from sjorssnoeren/api-documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorigin-response.js
More file actions
58 lines (51 loc) · 3.25 KB
/
origin-response.js
File metadata and controls
58 lines (51 loc) · 3.25 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict';
exports.handler = (event, context, callback) => {
const response = event.Records[0].cf.response;
const request = event.Records[0].cf.request;
const baseURI = 'https://docs.mollie.com'
function redirectTo(path) {
response.status = 302;
response.statusDescription = 'Found';
/* Drop the body, as it is not required for redirects */
response.body = '';
response.headers['location'] = [{ key: 'Location', value: baseURI + path }];
}
// Set new headers
response.headers['strict-transport-security'] = [{ key: 'Strict-Transport-Security', value: 'max-age=63072000; includeSubdomains; preload' }];
response.headers['content-security-policy'] = [{ key: 'Content-Security-Policy', value: "default-src 'self' assets.docs.mollie.com; img-src 'self' data: assets.docs.mollie.com https://images.ctfassets.net www.google-analytics.com https://www.gstatic.com https://www.googletagmanager.com; font-src cdn.mollie.com https://fonts.gstatic.com; script-src assets.docs.mollie.com https://www.googletagmanager.com www.google-analytics.com https://cdn.mxpnl.com 'sha256-FPgvfx+DeiJzmOHcDk2Iig1vKX6j8I0pKqPA7y33Xbc=' 'sha256-dSca7Fq9h/m8NPfsEIGN6QsOnwspkqCSOGFBGND+lps=' 'sha256-0M7Y8vfoB3jQRWrbd9UeLZorU2w32qynoWspDQn7U0g=' 'sha256-akWsBON1KU9NUSFengZbPuVOt+8KK3uSXcBP5Hc0sqQ=' 'sha256-nST9yaMPaU/xAS62+YWnvg5TxAXYYQm1Fn5Ybpu0AXM=' 'sha256-q/CGewBJOc0HL8ZusH9Fqnh2aZgLOH7lBvepoEVOrVw='; style-src assets.docs.mollie.com 'sha256-biLFinpqYMtWHmXfkA1BPeCY0/fNt46SAZ+BBk5YUog='; object-src 'none'; media-src 'none'; form-action 'none'; connect-src www.google-analytics.com https://api.mixpanel.com stats.g.doubleclick.net; report-uri https://mollie.report-uri.com/r/d/csp/enforce" }];
response.headers['x-content-type-options'] = [{ key: 'X-Content-Type-Options', value: 'nosniff' }];
response.headers['x-frame-options'] = [{ key: 'X-Frame-Options', value: 'DENY' }];
response.headers['x-xss-protection'] = [{ key: 'X-XSS-Protection', value: '1; mode=block' }];
response.headers['referrer-policy'] = [{ key: 'Referrer-Policy', value: 'same-origin' }];
response.headers['expect-ct'] = [{ key: 'Expect-CT', value: 'max-age=0, report-uri="https://mollie.report-uri.com/r/d/ct/reportOnly"' }];
delete response.headers["server"];
// Configure the URL redirects
switch (request.uri.replace(/\/$/, '')) {
case '/migrating-v1-to-v2':
redirectTo('/payments/migrating-v1-to-v2');
break;
case '/guides/multicurrency':
redirectTo('/payments/multicurrency');
break;
case '/guides/recurring':
redirectTo('/payments/recurring');
break;
case '/guides/payment-status-changes':
redirectTo('/payments/status-changes');
break;
case '/payments/webhooks':
redirectTo('/guides/webhooks');
break;
case '/security':
redirectTo('/guides/security');
break;
case '/reference/v2':
redirectTo('/reference/v2/payments-api/create-payment');
break;
case '/reference/v1':
redirectTo('/reference/v1/payments-api/create-payment');
break;
}
// Return modified response
callback(null, response);
};