Skip to content

Commit 44976c9

Browse files
committed
Fix code style
1 parent 8b9f3a4 commit 44976c9

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

basic-http/server.js

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const user = {
99
};
1010

1111
const server = http.createServer((req, res) => {
12+
res.writeHead(200, { 'Content-Type': 'text/plain' });
13+
res.writeHead(400, { 'Content-Type': 'text/plain' });
14+
res.end('111');
1215
res.end(
1316
`${user.name} said "Java is a crap!" and chiao from ${user.city}`
1417
);

native-advanced/server.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ for (const key in routing) {
3434
const router = (client) => {
3535
const { req: { url } } = client;
3636
let route = routing[url];
37-
const params = [];
37+
let params = [];
3838
if (!route) {
3939
for (const rx of matching) {
4040
params = url.match(rx[0]);
@@ -54,4 +54,4 @@ http.createServer((req, res) => {
5454
res.end(`${router({ req, res })}`);
5555
}).listen(PORT);
5656

57-
console.log(`Running server on port ${PORT}`)
57+
console.log(`Running server on port ${PORT}`);

native-async/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const types = {
3232

3333
const serve = (data, req, res) => {
3434
const type = typeof data;
35-
if (type === 'string') return res.end(data);
35+
if (type === 'string') return void res.end(data);
3636
const serializer = types[type];
3737
serializer([data, req, res], (ser) => serve(ser, req, res));
3838
};

native-simple/1-bad/logger.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'use strict';
22

3-
const writeLog = (req, res) => () => {
3+
const writeLog = (req) => () => {
44
const time = Date.now() - req.requestTime;
55
console.log(`${req.method} ${req.url} ${req.headers.referer} ${time}`);
66
};
77

88
const logger = (req, res, next) => {
99
req.requestTime = Date.now();
10-
res.on('close', writeLog(req, res));
10+
res.on('close', writeLog(req));
1111
next();
1212
};
1313

0 commit comments

Comments
 (0)