chore: fix s3 redirects with prefixes

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2022-08-17 18:14:26 +02:00
parent 91de5f5f28
commit b2b680bd2d
2 changed files with 99 additions and 24 deletions

View File

@@ -25,10 +25,16 @@ exports.handler = (event, context, callback) => {
}
const redirectsPrefixes = JSON.parse(`{{.RedirectsPrefixesJSON}}`);
for (let key in redirectsPrefixes) {
if (!request.uri.startsWith(key)) {
for (let x in redirectsPrefixes) {
const rp = redirectsPrefixes[x];
if (!request.uri.startsWith(`/${rp['prefix']}`)) {
continue;
}
let newlocation = "/";
if (rp['strip']) {
let re = new RegExp(`(^/${rp['prefix']})`, 'gi');
newlocation = request.uri.replace(re,'/');
}
//console.log(`redirect: ${request.uri} to ${redirectsPrefixes[key]}`);
const response = {
status: '301',
@@ -36,7 +42,7 @@ exports.handler = (event, context, callback) => {
headers: {
location: [{
key: 'Location',
value: redirectsPrefixes[key],
value: newlocation,
}],
},
}

View File

@@ -1,21 +1,90 @@
{
"/compliance/": "/",
"/datacenter/": "/",
"/ee/": "/",
"/v1.4/": "/",
"/v1.5/": "/",
"/v1.6/": "/",
"/v1.7/": "/",
"/v1.8/": "/",
"/v1.9/": "/",
"/v1.10/": "/",
"/v1.11/": "/",
"/v1.12/": "/",
"/v1.13/": "/",
"/v17.03/": "/",
"/v17.06/": "/",
"/v17.09/": "/",
"/v17.12/": "/",
"/v18.03/": "/",
"/v18.09/": "/"
}
[
{
"prefix": "compliance/",
"strip": false
},
{
"prefix": "datacenter/",
"strip": false
},
{
"prefix": "ee/",
"strip": false
},
{
"prefix": "v1.4/",
"strip": true
},
{
"prefix": "v1.5/",
"strip": true
},
{
"prefix": "v1.6/",
"strip": true
},
{
"prefix": "v1.7/",
"strip": true
},
{
"prefix": "v1.8/",
"strip": true
},
{
"prefix": "v1.9/",
"strip": true
},
{
"prefix": "v1.10/",
"strip": true
},
{
"prefix": "v1.11/",
"strip": true
},
{
"prefix": "v1.12/",
"strip": true
},
{
"prefix": "v1.13/",
"strip": true
},
{
"prefix": "v17.03/",
"strip": true
},
{
"prefix": "v17.06/enterprise/",
"strip": false
},
{
"prefix": "v17.06/",
"strip": true
},
{
"prefix": "v17.09/",
"strip": true
},
{
"prefix": "v17.12/",
"strip": true
},
{
"prefix": "v18.03/ee/",
"strip": false
},
{
"prefix": "v18.03/",
"strip": true
},
{
"prefix": "v18.09/ee/",
"strip": false
},
{
"prefix": "v18.09/",
"strip": true
}
]