Last active
October 23, 2024 13:35
-
-
Save teles/9fc2609aeebab217dbbad1e7bf7a9c8e to your computer and use it in GitHub Desktop.
Função cloudfront para redirecionamento de rotas em um app deployado no S3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://gist.github.com/teles/9fc2609aeebab217dbbad1e7bf7a9c8e | |
function handler(event) { | |
const request = event.request; | |
const uri = request.uri; | |
const queryString = request.querystring; | |
const basePath = '/onboarding'; | |
const validPaths = ['/onboarding', '/reset', '/limit']; | |
// Redireciona a raiz (/) para /onboarding | |
if (uri === '/' || uri === '') { | |
return { | |
statusCode: 302, | |
statusDescription: 'Found', | |
headers: { | |
location: { | |
value: `${basePath}${queryString ? '?' + queryString : ''}` | |
} | |
} | |
}; | |
} | |
// Redireciona os caminhos válidos para index.html | |
if (validPaths.includes(uri) || validPaths.some(path => uri.startsWith(path))) { | |
request.uri = '/index.html'; | |
} | |
return request; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment