Skip to content

Commit

Permalink
fix: test whether the storage proxy exists in storage.js
Browse files Browse the repository at this point in the history
  • Loading branch information
cnouguier committed Oct 26, 2021
1 parent 0657328 commit 90a41c1
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions build/express-gateway/plugins/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,27 @@ module.exports = {
const params = parseParams(req.params[0], pluginContext.settings.providers)
if (params.provider && params.bucket && params.key) {
const storageProxy = storageProxies[params.provider];
storageProxy.getObject({
Bucket: params.bucket,
Key: params.key,
Range: req.headers.range // Forward range requests
})
.on('httpHeaders', (statusCode, headers) => {
// Avoid catching event raised by connection initialization
// https://stackoverflow.com/questions/35782434/streaming-file-from-s3-with-express-including-information-on-length-and-filetype
if (headers['content-length']) {
res.status(statusCode);
res.set(headers);
} else logger.debug('Invalid response with status ' + statusCode)
})
.createReadStream()
.on('error', (err) => {
logger.debug(err);
return res.status(404).send(err);
})
.pipe(res);
if (storageProxy) {
storageProxy.getObject({
Bucket: params.bucket,
Key: params.key,
Range: req.headers.range // Forward range requests
})
.on('httpHeaders', (statusCode, headers) => {
// Avoid catching event raised by connection initialization
// https://stackoverflow.com/questions/35782434/streaming-file-from-s3-with-express-including-information-on-length-and-filetype
if (headers['content-length']) {
res.status(statusCode);
res.set(headers);
} else logger.debug('Invalid response with status ' + statusCode)
})
.createReadStream()
.on('error', (err) => {
logger.debug(err);
return res.status(404).send(err);
})
.pipe(res);
}
}
});
});
Expand Down

0 comments on commit 90a41c1

Please sign in to comment.