Skip to content

Commit

Permalink
refactor to use Promises and async/await
Browse files Browse the repository at this point in the history
This introduces slightly breaking changes to the signature of
s3rver.run() and s3rver.close() since they can now return promises if no
callback is provided.
  • Loading branch information
kherock committed Feb 13, 2019
1 parent 28d74d9 commit 22f0091
Show file tree
Hide file tree
Showing 10 changed files with 740 additions and 913 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"es6": true
},
"parserOptions": {
"ecmaVersion": 2017
"ecmaVersion": 2018
},
"extends": [
"eslint:recommended",
Expand Down
4 changes: 2 additions & 2 deletions bin/s3rver.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ if (program.key && program.cert) {
program.cert = fs.readFileSync(program.cert);
}

new S3rver(program).run((err, host, port) => {
new S3rver(program).run((err, { address, port }) => {
if (err) {
// eslint-disable-next-line no-console
console.error(err);
process.exit(1);
}
// eslint-disable-next-line no-console
console.log("S3rver listening on %s:%d", host, port);
console.log("S3rver listening on %s:%d", address, port);
});
4 changes: 2 additions & 2 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ module.exports = function(options) {
);

app.use((req, res, next) => {
const host = req.headers.host.split(":")[0];
const [host] = req.headers.host.split(":");

// Handle requests for <bucket>.s3(-<region>?).amazonaws.com, if they arrive.
const bucket = (/(.+)\.s3(-.+)?\.amazonaws\.com$/.exec(host) || [])[1];
const [, bucket] = /(.+)\.s3(-.+)?\.amazonaws\.com$/.exec(host) || [];
if (bucket) {
req.url = path.join("/", bucket, req.url);
} else if (
Expand Down
Loading

0 comments on commit 22f0091

Please sign in to comment.