Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- exports.handler = (event, context, callback) => {
- const request = event.Records[0].cf.request;
- const headers = request.headers;
- const uri = request.uri;
- let response = request;
- let url = '/';
- if (headers['cloudfront-viewer-country']) {
- const countryCode = headers['cloudfront-viewer-country'][0].value;
- if (countryCode != 'PT') {
- url = '/w/';
- }
- }
- if(uri !== url){
- response = {
- status: '302',
- statusDescription: 'Found',
- headers: {
- location: [{
- key: 'Location',
- value: url,
- }],
- },
- };
- }
- callback(null, response);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement