mirror of
https://github.com/eledio-cloud/standard-redirects-for-cloudfront.git
synced 2025-10-30 16:12:30 +01:00
fixed a problem with network-path references (see https://datatracker.ietf.org/doc/html/rfc3986#section-4.2), updated mocha
This commit is contained in:
8
index.js
8
index.js
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
/*
|
||||
Copyright 2017-2019 DigitalSailors e.K.
|
||||
Copyright 2017-2021 DigitalSailors e.K.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -25,23 +25,25 @@ exports.handler = (event, context, callback) => {
|
||||
request.uri += 'index.html';
|
||||
callback(null, request);
|
||||
} else if (prefixPath = request.uri.match('(.+)/index.html')) {
|
||||
const modifiedPrefixPath = prefixPath[1].replace(/^\/+/, '/');
|
||||
const response = {
|
||||
status: '301',
|
||||
statusDescription: 'Found',
|
||||
headers: {
|
||||
location: [{
|
||||
key: 'Location', value: prefixPath[1] + '/',
|
||||
key: 'Location', value: modifiedPrefixPath + '/',
|
||||
}],
|
||||
}
|
||||
};
|
||||
callback(null, response);
|
||||
} else if (request.uri.match('/[^/.]+$')) {
|
||||
const modifiedRequestURI = request.uri.replace(/^\/+/, '/');
|
||||
const response = {
|
||||
status: '301',
|
||||
statusDescription: 'Found',
|
||||
headers: {
|
||||
location: [{
|
||||
key: 'Location', value: request.uri + '/',
|
||||
key: 'Location', value: modifiedRequestURI + '/',
|
||||
}],
|
||||
}
|
||||
};
|
||||
|
||||
1807
package-lock.json
generated
Normal file
1807
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "standard-redirects-for-cloudfront",
|
||||
"version": "1.4.0",
|
||||
"version": "1.4.1",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
@@ -11,7 +11,6 @@
|
||||
"package": "aws cloudformation package --template-file sam.yaml --output-template-file standard-redirects-for-cloudfront-sam.yaml --s3-bucket public.digital-sailors.de --s3-prefix serverless-application-repo/standard-redirects-for-cloudfront",
|
||||
"package-test": "aws cloudformation package --template-file sam.yaml --output-template-file standard-redirects-for-cloudfront-sam-test.yaml --s3-bucket demo.digital-sailors.work --s3-prefix serverless-application-repo/standard-redirects-for-cloudfront-test"
|
||||
},
|
||||
"dependencies": {},
|
||||
"license": "Apache-2.0",
|
||||
"author": {
|
||||
"name": "DigitalSailors e.K.",
|
||||
@@ -19,6 +18,6 @@
|
||||
"url": "https://www.digital-sailors.de"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "^4.0.1"
|
||||
"mocha": "^8.4.0"
|
||||
}
|
||||
}
|
||||
|
||||
35
test/unit.js
35
test/unit.js
@@ -56,7 +56,7 @@ describe('Testing index.js', function() {
|
||||
done(assert.strictEqual(data.uri, '/foo/bar/index.html'));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('/foo -> external redirect (301) -> /foo/', function(done) {
|
||||
const event = {
|
||||
Records:[{ cf: {
|
||||
@@ -65,7 +65,7 @@ describe('Testing index.js', function() {
|
||||
}
|
||||
} }] };
|
||||
index.handler(event, {}, (err, data) => {
|
||||
done(assert.strictEqual(data.status, '301')
|
||||
done(assert.strictEqual(data.status, '301')
|
||||
|| assert.strictEqual(data.headers.location[0].key, 'Location')
|
||||
|| assert.strictEqual(data.headers.location[0].value, '/foo/'));
|
||||
});
|
||||
@@ -101,9 +101,38 @@ describe('Testing index.js', function() {
|
||||
}
|
||||
} }] };
|
||||
index.handler(event, {}, (err, data) => {
|
||||
done(assert.strictEqual(data.status, '301')
|
||||
done(assert.strictEqual(data.status, '301')
|
||||
|| assert.strictEqual(data.headers.location[0].key, 'Location')
|
||||
|| assert.strictEqual(data.headers.location[0].value, '/foo/'));
|
||||
});
|
||||
});
|
||||
|
||||
it('//foo/index.html -> external redirect (301) -> /foo/', function(done) {
|
||||
const event = {
|
||||
Records:[{ cf: {
|
||||
request: {
|
||||
uri: '//foo/index.html'
|
||||
}
|
||||
} }] };
|
||||
index.handler(event, {}, (err, data) => {
|
||||
done(assert.strictEqual(data.status, '301')
|
||||
|| assert.strictEqual(data.headers.location[0].key, 'Location')
|
||||
|| assert.strictEqual(data.headers.location[0].value, '/foo/'));
|
||||
});
|
||||
});
|
||||
|
||||
it('///foo -> external redirect (301) -> /foo/', function(done) {
|
||||
const event = {
|
||||
Records:[{ cf: {
|
||||
request: {
|
||||
uri: '//foo/index.html'
|
||||
}
|
||||
} }] };
|
||||
index.handler(event, {}, (err, data) => {
|
||||
done(assert.strictEqual(data.status, '301')
|
||||
|| assert.strictEqual(data.headers.location[0].key, 'Location')
|
||||
|| assert.strictEqual(data.headers.location[0].value, '/foo/'));
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user