Skip to content

Instantly share code, notes, and snippets.

@teles
Last active October 23, 2024 13:35
Show Gist options
  • Save teles/9fc2609aeebab217dbbad1e7bf7a9c8e to your computer and use it in GitHub Desktop.
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
// 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