Skip to content

Commit 4c9f300

Browse files
committed
Use prettier for formatting
1 parent cdfe186 commit 4c9f300

28 files changed

+249
-124
lines changed

.prettierrc

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

examples/echo/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ const server = http.createServer();
2525
server.addListener('request', function(req, res) {
2626
static_directory.serve(req, res);
2727
});
28-
server.addListener('upgrade', function(req,res){
28+
server.addListener('upgrade', function(req, res) {
2929
res.end();
3030
});
3131

3232
sockjs_echo.attach(server);
3333

34-
console.log(' [*] Listening on 0.0.0.0:9999' );
34+
console.log(' [*] Listening on 0.0.0.0:9999');
3535
server.listen(9999, '0.0.0.0');

examples/express/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ sockjs_echo.on('connection', function(conn) {
1919

2020
// 2. Express server
2121
const app = express();
22-
app.get('/', function (req, res) {
22+
app.get('/', function(req, res) {
2323
res.sendFile(__dirname + '/index.html');
2424
});
2525

2626
const server = http.createServer(app);
2727
sockjs_echo.attach(server);
2828

2929
server.listen(9999, '0.0.0.0', () => {
30-
console.log(' [*] Listening on 0.0.0.0:9999' );
30+
console.log(' [*] Listening on 0.0.0.0:9999');
3131
});

examples/koa/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const path = require('path');
88

99
// 1. Echo sockjs server
1010
const sockjs_opts = {
11-
prefix:'/echo',
11+
prefix: '/echo',
1212
sockjs_url: 'http://cdn.jsdelivr.net/sockjs/1/sockjs.min.js'
1313
};
1414
const sockjs_echo = sockjs.createServer(sockjs_opts);
@@ -33,4 +33,4 @@ const server = http.createServer(app.callback());
3333
sockjs_echo.attach(server);
3434

3535
server.listen(9999, '0.0.0.0');
36-
console.log(' [*] Listening on 0.0.0.0:9999' );
36+
console.log(' [*] Listening on 0.0.0.0:9999');

examples/multiplex/server.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ann.on('connection', function(conn) {
2525

2626
const bob = multiplexer.registerChannel('bob');
2727
bob.on('connection', function(conn) {
28-
conn.write('Bob doesn\'t agree.');
28+
conn.write("Bob doesn't agree.");
2929
conn.on('data', function(data) {
3030
conn.write('Bob says no to: ' + data);
3131
});
@@ -40,13 +40,13 @@ carl.on('connection', function(conn) {
4040

4141
// 3. Express server
4242
const app = express();
43-
app.get('/', function (req, res) {
43+
app.get('/', function(req, res) {
4444
res.sendFile(__dirname + '/index.html');
4545
});
4646

4747
const server = http.createServer(app);
4848
service.attach(server);
4949

5050
server.listen(9999, '0.0.0.0', () => {
51-
console.log(' [*] Listening on 0.0.0.0:9999' );
51+
console.log(' [*] Listening on 0.0.0.0:9999');
5252
});

lib/handlers.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = {
1414
},
1515

1616
handle_405(req, res, methods) {
17-
res.writeHead(405, { 'Allow': methods.join(', ') });
17+
res.writeHead(405, { Allow: methods.join(', ') });
1818
res.end();
1919
},
2020

@@ -31,8 +31,11 @@ module.exports = {
3131
res.writeHead(500);
3232
res.end('500 - Internal Server Error');
3333
} catch (ex) {
34-
this.options.log('error', `Exception on "${req.method} ${req.url}" in filter "${req.last_fun}":\n${ex.stack || ex}`);
34+
this.options.log(
35+
'error',
36+
`Exception on "${req.method} ${req.url}" in filter "${req.last_fun}":\n${ex.stack || ex}`
37+
);
3538
}
3639
}
37-
},
40+
}
3841
};

lib/iframe.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const iframe_template = `<!DOCTYPE html>
2020
</body>
2121
</html>`;
2222

23-
2423
module.exports = {
2524
iframe(req, res, _head, next) {
2625
const context = {
@@ -34,8 +33,7 @@ module.exports = {
3433

3534
const quoted_md5 = `"${utils.md5_hex(content)}"`;
3635

37-
if ('if-none-match' in req.headers &&
38-
req.headers['if-none-match'] === quoted_md5) {
36+
if ('if-none-match' in req.headers && req.headers['if-none-match'] === quoted_md5) {
3937
res.statusCode = 304;
4038
res.end();
4139
return next();

lib/info.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
transports: this.options.transports,
1212
origins: this.options.disable_cors ? undefined : ['*:*'],
1313
cookie_needed: !!this.options.jsessionid,
14-
entropy: utils.random32(),
14+
entropy: utils.random32()
1515
};
1616
// Users can specify a new base URL which further requests will be made
1717
// against. For example, it may contain a randomized domain name to

lib/listener.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ module.exports.generateDispatcher = function generateDispatcher(options) {
1111
const p = s => new RegExp(`^${options.prefix}${s}[/]?$`);
1212
const t = s => [p(`/([^/.]+)/([^/.]+)${s}`), 'server', 'session'];
1313
const prefix_dispatcher = [
14-
['GET', p(''), [handlers.welcome_screen]],
14+
['GET', p(''), [handlers.welcome_screen]],
1515
['OPTIONS', p('/info'), [middleware.h_sid, middleware.xhr_cors, info.info_options]],
16-
['GET', p('/info'), [middleware.xhr_cors, middleware.h_no_cache, info.info]],
16+
['GET', p('/info'), [middleware.xhr_cors, middleware.h_no_cache, info.info]]
1717
];
1818
if (!options.disable_cors) {
1919
prefix_dispatcher.push(['GET', p('/iframe[0-9-.a-z_]*.html'), [iframe.iframe]]);

lib/middleware.js

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,19 @@ module.exports = {
2828
next();
2929
},
3030

31-
cache_for(res, duration=(365 * 24 * 60 * 60)) {
31+
cache_for(res, duration = 365 * 24 * 60 * 60) {
3232
res.cache_for = duration;
33-
const exp = new Date(Date.now() + (duration * 1000));
33+
const exp = new Date(Date.now() + duration * 1000);
3434
res.setHeader('Cache-Control', `public, max-age=${duration}`);
3535
res.setHeader('Expires', exp.toGMTString());
3636
},
3737

3838
log_request(req, res, _head, next) {
3939
const td = Date.now() - req.start_date;
40-
this.options.log('info', `${req.method} ${req.url} ${td}ms ${res.finished ? res.statusCode : '(unfinished)'}`);
40+
this.options.log(
41+
'info',
42+
`${req.method} ${req.url} ${td}ms ${res.finished ? res.statusCode : '(unfinished)'}`
43+
);
4144
next();
4245
},
4346

@@ -48,16 +51,16 @@ module.exports = {
4851
}
4952

5053
switch ((req.headers['content-type'] || '').split(';')[0]) {
51-
case 'application/x-www-form-urlencoded':
52-
req.body = querystring.parse(body);
53-
break;
54-
case 'text/plain':
55-
case '':
56-
req.body = body;
57-
break;
58-
default:
59-
this.options.log('error', `Unsupported content-type ${req.headers['content-type']}`);
60-
break;
54+
case 'application/x-www-form-urlencoded':
55+
req.body = querystring.parse(body);
56+
break;
57+
case 'text/plain':
58+
case '':
59+
req.body = body;
60+
break;
61+
default:
62+
this.options.log('error', `Unsupported content-type ${req.headers['content-type']}`);
63+
break;
6164
}
6265
next();
6366
});
@@ -70,17 +73,17 @@ module.exports = {
7073
}
7174

7275
switch ((req.headers['content-type'] || '').split(';')[0]) {
73-
case 'text/plain':
74-
case 'T':
75-
case 'application/json':
76-
case 'application/xml':
77-
case '':
78-
case 'text/xml':
79-
req.body = body;
80-
break;
81-
default:
82-
this.options.log('error', `Unsupported content-type ${req.headers['content-type']}`);
83-
break;
76+
case 'text/plain':
77+
case 'T':
78+
case 'application/json':
79+
case 'application/xml':
80+
case '':
81+
case 'text/xml':
82+
req.body = body;
83+
break;
84+
default:
85+
this.options.log('error', `Unsupported content-type ${req.headers['content-type']}`);
86+
break;
8487
}
8588
next();
8689
});
@@ -97,7 +100,7 @@ module.exports = {
97100
},
98101

99102
xhr_options(req, res, _head, next) {
100-
res.statusCode = 204; // No content
103+
res.statusCode = 204; // No content
101104
module.exports.cache_for(res);
102105
res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, POST');
103106
res.setHeader('Access-Control-Max-Age', res.cache_for);
@@ -124,5 +127,5 @@ module.exports = {
124127
res.setHeader('Access-Control-Allow-Headers', headers);
125128
}
126129
next();
127-
},
130+
}
128131
};

0 commit comments

Comments
 (0)