Skip to content

Commit 3ec6b07

Browse files
authored
Merge pull request #56 from bobisjan/prettier
Add Prettier
2 parents dec01ce + 3aec19f commit 3ec6b07

File tree

8 files changed

+168
-235
lines changed

8 files changed

+168
-235
lines changed

.eslintrc.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module.exports = {
33
parserOptions: {
44
ecmaVersion: 2017,
55
},
6-
extends: ['eslint:recommended', 'plugin:node/recommended'],
7-
plugins: ['node'],
6+
extends: ['eslint:recommended', 'plugin:node/recommended', 'plugin:prettier/recommended'],
7+
plugins: ['node', 'prettier'],
88
env: {
99
node: true,
1010
es6: true,
@@ -18,5 +18,5 @@ module.exports = {
1818
extends: ['plugin:mocha/recommended'],
1919
plugins: ['mocha'],
2020
},
21-
]
22-
};
21+
],
22+
};

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"printWidth": 100,
4+
"trailingComma": "es5"
5+
}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@
3131
"chai-as-promised": "^7.1.1",
3232
"ember-cli": "^2.7.0",
3333
"eslint": "^6.8.0",
34+
"eslint-config-prettier": "^6.9.0",
3435
"eslint-plugin-mocha": "^6.2.2",
3536
"eslint-plugin-node": "^11.0.0",
37+
"eslint-plugin-prettier": "^3.1.2",
3638
"express": "^4.13.4",
3739
"mocha": "^5.0.0",
40+
"prettier": "^1.19.1",
3841
"request-promise": "^4.2.1"
3942
},
4043
"dependencies": {

src/index.js

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
43
function fastbootExpressMiddleware(distPath, options) {
54
let opts = options;
65

@@ -22,51 +21,51 @@ function fastbootExpressMiddleware(distPath, options) {
2221
let FastBoot = require('fastboot');
2322
fastboot = new FastBoot({
2423
distPath: opts.distPath,
25-
resilient: opts.resilient
24+
resilient: opts.resilient,
2625
});
2726
}
2827

2928
return function(req, res, next) {
3029
let path = req.url;
31-
fastboot.visit(path, { request: req, response: res })
32-
.then(success, failure);
30+
fastboot.visit(path, { request: req, response: res }).then(success, failure);
3331

3432
function success(result) {
3533
let responseBody = opts.chunkedResponse ? result.chunks() : result.html();
3634

37-
responseBody.then(body => {
38-
let headers = result.headers;
39-
let statusMessage = result.error ? 'NOT OK ' : 'OK ';
40-
41-
for (var pair of headers.entries()) {
42-
res.set(pair[0], pair[1]);
43-
}
44-
45-
if (result.error) {
46-
log("RESILIENT MODE CAUGHT:", result.error.stack);
47-
next(result.error);
48-
}
49-
50-
log(result.statusCode, statusMessage + path);
51-
res.status(result.statusCode);
52-
53-
if (typeof body === 'string') {
54-
res.send(body);
55-
} else if (result.error) {
56-
res.send(body[0]);
57-
} else {
58-
body.forEach(chunk => res.write(chunk));
59-
res.end();
60-
}
61-
})
62-
.catch(error => {
63-
res.status(500);
64-
next(error);
65-
});
35+
responseBody
36+
.then(body => {
37+
let headers = result.headers;
38+
let statusMessage = result.error ? 'NOT OK ' : 'OK ';
39+
40+
for (var pair of headers.entries()) {
41+
res.set(pair[0], pair[1]);
42+
}
43+
44+
if (result.error) {
45+
log('RESILIENT MODE CAUGHT:', result.error.stack);
46+
next(result.error);
47+
}
48+
49+
log(result.statusCode, statusMessage + path);
50+
res.status(result.statusCode);
51+
52+
if (typeof body === 'string') {
53+
res.send(body);
54+
} else if (result.error) {
55+
res.send(body[0]);
56+
} else {
57+
body.forEach(chunk => res.write(chunk));
58+
res.end();
59+
}
60+
})
61+
.catch(error => {
62+
res.status(500);
63+
next(error);
64+
});
6665
}
6766

6867
function failure(error) {
69-
if (error.name === "UnrecognizedURLError") {
68+
if (error.name === 'UnrecognizedURLError') {
7069
next();
7170
} else {
7271
res.status(500);
@@ -85,10 +84,10 @@ function _log(statusCode, message, startTime) {
8584

8685
if (startTime) {
8786
let diff = Date.now() - startTime;
88-
message = message + chalk.blue(" " + diff + "ms");
87+
message = message + chalk.blue(' ' + diff + 'ms');
8988
}
9089

91-
console.log(chalk.blue(now.toISOString()) + " " + chalk[color](statusCode) + " " + message);
90+
console.log(chalk.blue(now.toISOString()) + ' ' + chalk[color](statusCode) + ' ' + message);
9291
}
9392

9493
module.exports = fastbootExpressMiddleware;

test/helpers/test-http-server.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

3-
const express = require('express');
4-
const request = require('request-promise');
3+
const express = require('express');
4+
const request = require('request-promise');
55

66
let serverID = 0;
77

@@ -27,14 +27,15 @@ class TestHTTPServer {
2727
}
2828

2929
if (options.recoverErrors) {
30-
app.use((err, req, res, next) => { // eslint-disable-line no-unused-vars
30+
// eslint-disable-next-line no-unused-vars
31+
app.use((err, req, res, next) => {
3132
res.set('x-test-recovery', 'recovered response');
3233
res.status(200);
3334
res.send('hello world');
3435
});
3536
}
3637

37-
return new Promise((resolve) => {
38+
return new Promise(resolve => {
3839
let port = options.port || 3000;
3940
let host = options.host || 'localhost';
4041

@@ -46,7 +47,7 @@ class TestHTTPServer {
4647
this.info = {
4748
host: host,
4849
port: port,
49-
listener: listener
50+
listener: listener,
5051
};
5152

5253
resolve(this.info);
@@ -61,7 +62,7 @@ class TestHTTPServer {
6162
if (options && options.resolveWithFullResponse) {
6263
return request({
6364
resolveWithFullResponse: options.resolveWithFullResponse,
64-
uri: url + urlPath
65+
uri: url + urlPath,
6566
});
6667
}
6768

0 commit comments

Comments
 (0)