Skip to content
This repository has been archived by the owner on Sep 25, 2019. It is now read-only.

Commit

Permalink
update(api): enable Google Edge caching.
Browse files Browse the repository at this point in the history
Relates to #104
  • Loading branch information
Splaktar committed Mar 18, 2017
1 parent eb62552 commit 466e6c9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/controllers/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 466e6c9

Please sign in to comment.