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

Commit

Permalink
Add caching (2 hours by default)
Browse files Browse the repository at this point in the history
  • Loading branch information
aluxian committed Feb 10, 2017
1 parent 17a6a76 commit 23aee82
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

A simple node.js server for Squirrel.Mac and Squirrel.Windows which uses GitHub releases. It also has an endpoint for Linux.

The server doesn't do any caching, and its responses don't include caching headers. Use a service like CloudFlare to cache requests and minimise load.
> The server doesn't do any caching, and its responses don't include caching headers. Use a service like CloudFlare to cache requests and minimise load.
> CHANGED: From v0.6, I added server-side caching.
> Make sure you tag your releases as `vX.X.X` and not just `X.X.X`.
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "squirrel-updates-server",
"version": "0.5.3",
"version": "0.6.0",
"description": "A simple node.js server for Squirrel.Mac and Squirrel.Windows which uses GitHub releases.",
"private": true,
"main": "index.js",
Expand Down Expand Up @@ -29,6 +29,7 @@
},
"homepage": "https://github.com/Aluxian/squirrel-updates-server#readme",
"dependencies": {
"apicache": "0.8.3",
"babel-cli": "6.7.7",
"babel-plugin-array-includes": "2.0.3",
"babel-plugin-transform-es2015-classes": "6.7.7",
Expand Down
3 changes: 2 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ export default {
defaultChannel: 'stable',
downloadsCountOffset: parseInt(process.env.DOWNLOADS_COUNT_OFFSET || '0') || 0,
excludeDrafts: JSON.parse(process.env.EXCLUDE_DRAFTS || 'true'),
excludePrereleases: JSON.parse(process.env.EXCLUDE_PRERELEASES || 'false')
excludePrereleases: JSON.parse(process.env.EXCLUDE_PRERELEASES || 'false'),
cacheTTL: '2 hours'
};
29 changes: 17 additions & 12 deletions src/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import express from 'express';
import apicache from 'apicache';
import morgan from 'morgan';
import raven from 'raven';

Expand Down Expand Up @@ -27,19 +28,23 @@ if (ravenClient) {
app.use(raven.middleware.express.requestHandler(ravenClient));
}

app.get('/', asyncHandler(homeCtrl.main));
app.get('/update/darwin', asyncHandler(updateCtrl.darwin));
app.get('/update/win32/portable', asyncHandler(updateCtrl.win32_portable));
app.get('/update/win32/:file', asyncHandler(updateCtrl.win32_file));
app.get('/update/linux', asyncHandler(updateCtrl.linux));
app.get('/update/:channel/darwin', asyncHandler(updateCtrl.darwin));
app.get('/update/:channel/win32/portable', asyncHandler(updateCtrl.win32_portable));
app.get('/update/:channel/win32/:file', asyncHandler(updateCtrl.win32_file));
app.get('/update/:channel/linux', asyncHandler(updateCtrl.linux));
const cache = () => {
return apicache.middleware(config.cacheTTL);
};

app.get('/', cache(), asyncHandler(homeCtrl.main));
app.get('/update/darwin', cache(), asyncHandler(updateCtrl.darwin));
app.get('/update/win32/portable', cache(), asyncHandler(updateCtrl.win32_portable));
app.get('/update/win32/:file', cache(), asyncHandler(updateCtrl.win32_file));
app.get('/update/linux', cache(), asyncHandler(updateCtrl.linux));
app.get('/update/:channel/darwin', cache(), asyncHandler(updateCtrl.darwin));
app.get('/update/:channel/win32/portable', cache(), asyncHandler(updateCtrl.win32_portable));
app.get('/update/:channel/win32/:file', cache(), asyncHandler(updateCtrl.win32_file));
app.get('/update/:channel/linux', cache(), asyncHandler(updateCtrl.linux));
app.get('/download/mirror/:mirror/latest', asyncHandler(downloadCtrl.latestMirror));
app.get('/download/:platform/latest', asyncHandler(downloadCtrl.latest));
app.get('/stats', asyncHandler(statsCtrl.main));
app.get('/badge/:type.svg', asyncHandler(badgeCtrl.main));
app.get('/download/:platform/latest', cache(), asyncHandler(downloadCtrl.latest));
app.get('/stats', cache(), asyncHandler(statsCtrl.main));
app.get('/badge/:type.svg', cache(), asyncHandler(badgeCtrl.main));

app.use(errorHandler1);
if (ravenClient) {
Expand Down

0 comments on commit 23aee82

Please sign in to comment.