Skip to content

Instantly share code, notes, and snippets.

@TheSkorm
Created May 27, 2018 01:35
Show Gist options
  • Select an option

  • Save TheSkorm/2621ae7bc770b40f3627a5014a732be8 to your computer and use it in GitHub Desktop.

Select an option

Save TheSkorm/2621ae7bc770b40f3627a5014a732be8 to your computer and use it in GitHub Desktop.
'use strict';
exports.handler = (event, context, callback) => {
/*
* Generate HTTP redirect response with 302 status code and Location header.
*/
const request = event.Records[0].cf.request;
if (request.uri.startsWith('/aprs/') ){
var sonde = request.uri.replace(/^\/aprs\//,"");
var specific_response = {
status: '302',
statusDescription: 'Found',
headers: {
location: [{
key: 'Location',
value: 'https://aprs.fi/#!call='+sonde+'&timerange=36000&tail=36000'
}],
},
};
callback(null, specific_response);
return;
}
if (request.uri !== '/' ){
var sonde = request.uri.replace(/^\//,"");
var specific_response = {
status: '302',
statusDescription: 'Found',
headers: {
location: [{
key: 'Location',
value: 'https://tracker.sondehub.org/?sondehub=1#!mt=roadmap&f=RS_'+sonde+'&mz=9&qm=All&q=RS_'+sonde
}],
},
};
callback(null, specific_response);
return;
}
if (request.querystring !== '' && request.querystring !== undefined) {
// do not process if this is not an A-B test request
callback(null, request);
return;
}
const response = {
status: '302',
statusDescription: 'Found',
headers: {
location: [{
key: 'Location',
value: 'https://tracker.sondehub.org/?sondehub=1#!mt=roadmap&f=none&mz=2&qm=6_hours&q=RS_*;*chase',
}],
},
};
callback(null, response);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment