reverse index.html implemented

This commit is contained in:
captain-digitalsailors
2017-12-23 10:40:57 +01:00
parent 5694b8d323
commit 3269258ece
5 changed files with 182 additions and 6 deletions

View File

@@ -20,13 +20,26 @@ const http = require('http');
exports.handler = (event, context, callback) => {
const request = event.Records[0].cf.request;
if (request.uri.endsWith('/')) {
let prefixPath; // needed for 2nd condition
if (request.uri.match('.+/$')) {
request.uri += 'index.html';
callback(null, request);
} else if (request.uri.match('/[^/.]*$')) {
} else if (prefixPath = request.uri.match('(.+)/index.html')) {
const response = {
status: '302',
status: '301',
statusDescription: 'Found',
headers: {
location: [{
key: 'Location', value: prefixPath[1] + '/',
}],
}
};
callback(null, response);
} else if (request.uri.match('/[^/.]+$')) {
const response = {
status: '301',
statusDescription: 'Found',
headers: {
location: [{