Skip to content

Commit

Permalink
Merge pull request #2 from blue-white-inc/no-cache-proxy
Browse files Browse the repository at this point in the history
No cache proxy
  • Loading branch information
jdinh1 authored May 31, 2022
2 parents 0d33fce + 4bc665c commit f0c73c2
Show file tree
Hide file tree
Showing 5 changed files with 2,586 additions and 13 deletions.
3 changes: 2 additions & 1 deletion bin/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ var myNuts = nuts.Nuts({
timeout: process.env.VERSIONS_TIMEOUT,
cache: process.env.VERSIONS_CACHE,
refreshSecret: process.env.GITHUB_SECRET,
proxyAssets: !Boolean(process.env.DONT_PROXY_ASSETS)
proxyAssets: !Boolean(process.env.DONT_PROXY_ASSETS),
behindReverseProxy: Boolean(process.env.BEHIND_REVERSE_PROXY),
});

// Control access to API
Expand Down
17 changes: 8 additions & 9 deletions lib/backends/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,17 @@ Backend.prototype.serveAsset = function(asset, req, res) {
res.header('Content-Length', asset.size);
res.attachment(asset.filename);

// Key exists
if (that.cache.has(cacheKey)) {
return that.cache.getStream(cacheKey)
.then(outputStream);
}

return that.getAssetStream(asset)
.then(function(stream) {
if (that.opts.behindReverseProxy) {
return Q(stream
.on('response', function(res) {
delete res.headers['etag'];
res.headers['cache-control'] = 'max-age=7200'
})
.pipe(res));
}
return Q.all([
// Cache the stream
that.cache.set(cacheKey, stream),

// Send the stream to the user
outputStream(stream)
]);
Expand Down
3 changes: 2 additions & 1 deletion lib/backends/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ GitHubBackend.prototype.getAssetStream = function(asset) {
uri: asset.raw.url,
method: 'get',
headers: headers,
auth: httpAuth
auth: httpAuth,
encoding: null
}));
};

Expand Down
Loading

0 comments on commit f0c73c2

Please sign in to comment.