Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. 'use strict';
  2.  
  3. exports.handler = (event, context, callback) => {
  4. const request = event.Records[0].cf.request;
  5. const headers = request.headers;
  6. const uri = request.uri;
  7. let response = request;
  8.  
  9. let url = '/';
  10. if (headers['cloudfront-viewer-country']) {
  11. const countryCode = headers['cloudfront-viewer-country'][0].value;
  12. if (countryCode != 'PT') {
  13. url = '/w/';
  14. }
  15. }
  16. if(uri !== url){
  17. response = {
  18. status: '302',
  19. statusDescription: 'Found',
  20. headers: {
  21. location: [{
  22. key: 'Location',
  23. value: url,
  24. }],
  25. },
  26. };
  27. }
  28. callback(null, response);
  29. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement