UNPKG

aws-spa

Version:

A no-brainer script to deploy a single page app on AWS

47 lines (39 loc) 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.noDefaultRootObjectFunctions = void 0; var _constants = require("./constants"); const noDefaultRootObjectFunctions = { [_constants.NO_DEFAULT_ROOT_OBJECT_REDIRECTION_COLOR]: ` async function handler(event) { const request = event.request const uri = request.uri if (uri.endsWith('index.html/') || uri.endsWith('index.html')) { return request } const splitURI = uri.split('/') const isNotAnAsset = !splitURI[splitURI.length - 1].includes('.') const isOnlyBranchName = splitURI.length === 1 const hasNoSlashAtTheEnd = !uri.endsWith('/') // make sure there is a slash before the hash router's "#/" to avoid "url.com/branch#/path" case if (isOnlyBranchName && hasNoSlashAtTheEnd && isNotAnAsset) { return { statusCode: 302, statusDescription: 'Found', headers: { location: { value: request.uri + '/', }, }, } } // add index.html if the URI is not an asset if (isNotAnAsset) { request.uri += 'index.html' } return request } ` }; exports.noDefaultRootObjectFunctions = noDefaultRootObjectFunctions;