all files / apigateway-utils/src/ SilvermineResponseBuilder.js

100% Statements 16/16
100% Branches 0/0
100% Functions 2/2
100% Lines 16/16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32                               
'use strict';
 
var RB = require('./ResponseBuilder');
 
module.exports = RB.extend({
 
   init: function() {
      var now = new Date(),
          builtOn = [];
 
      this._super();
      this.allowCORS();
      this.supportJSONP('callback');
      this.cacheForMinutes(30);
 
      builtOn.push(process.env.AWS_REGION);
      builtOn.push(process.env.AWS_LAMBDA_FUNCTION_NAME);
      builtOn.push(process.env.AWS_LAMBDA_FUNCTION_VERSION);
      builtOn.push(process.env.DEPLOYED_CODE_VERSION);
 
      this.header('X-Built-On', builtOn.join(':'));
      this.header('X-Page-Built', now.toUTCString());
   },
 
   toResponse: function(req) {
      this.header('X-Elapsed-Millis', new Date().getTime() - req.started());
      this.header('X-RequestID', req.context('awsRequestId'));
      return this._super(req);
   },
 
});