all files / src/ SilvermineResponseBuilder.js

100% Statements 17/17
100% Branches 0/0
100% Functions 2/2
100% Lines 17/17
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 33 34 35 36                            13× 13× 13×          
'use strict';
 
var _ = require('underscore'),
    RB = require('./ResponseBuilder'),
    CONTENT_TYPES = require('./contentTypes');
 
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.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);
   },
 
});
 
_.extend(module.exports, CONTENT_TYPES);