diff --git a/lib/controllers/api/index.js b/lib/controllers/api/index.js index 04f1978..32bb244 100755 --- a/lib/controllers/api/index.js +++ b/lib/controllers/api/index.js @@ -15,6 +15,7 @@ var express = require('express'), CacherRedis = require('cacher-redis'); module.exports = function (app) { + const EDGE_CACHE_MAX_AGE = 3600; // 1 hr var versions = []; var rateHandler; var cacher; @@ -131,6 +132,19 @@ module.exports = function (app) { rm(req, res, next); }; + + /** + * Enable Google Edge caching for our API + * @param req + * @param res + * @param next + */ + var edgeCache = function (req, res, next) { + res.header('Cache-Control', 'public, max-age=' + EDGE_CACHE_MAX_AGE); + res.header('Pragma', 'Public'); + next(); + }; + require('fs').readdirSync(__dirname + '/').forEach(function (file) { if (file.match(/.+\.js/g) === null) { var version = file; @@ -142,6 +156,7 @@ module.exports = function (app) { impl.use(apiKeyMiddleware); impl.use(rateMiddleware); impl.use(analyticsMiddleware(version)); + impl.use(edgeCache); impl.route = function (method, path, metadata) { var args = Array.prototype.slice.call(arguments);