Skip to content

Commit 3589d23

Browse files
committed
Updated docs, latest release (0.8.2)
1 parent 0c8c93f commit 3589d23

File tree

6 files changed

+34
-37
lines changed

6 files changed

+34
-37
lines changed

Router.html

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.

Router.js.html

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181

8282
const result = this.stack.exec(this.req, this.res);
8383

84-
/* istanbul ignore if (tested in: test/e2e/async) */
8584
if (isPromise(result)) {
8685
return result.then(() => this.res.data());
8786
}
@@ -313,23 +312,21 @@
313312
function loadRoutes(router) {
314313
const routeDir = moduleParent() + '/routes';
315314

316-
if (fs.existsSync(routeDir)) {
317-
const files = getRoutes(routeDir);
315+
const files = getRoutes(routeDir);
318316

319-
files.forEach(file => {
320-
file = path.relative(routeDir, file);
321-
const {dir, name} = path.parse(file);
317+
files.forEach(file => {
318+
file = path.relative(routeDir, file);
319+
const {dir, name} = path.parse(file);
322320

323-
const filePath = [dir, name].join('/');
324-
const route = require(`${routeDir}/${filePath}`);
321+
const filePath = [dir, name].join('/');
322+
const route = require(`${routeDir}/${filePath}`);
325323

326-
route.path = (
327-
filePath[0] === '/' ? filePath : `/${filePath}`
328-
).toLowerCase();
324+
route.path = (
325+
filePath[0] === '/' ? filePath : `/${filePath}`
326+
).toLowerCase();
329327

330-
Route(router, route);
331-
});
332-
}
328+
Route(router, route);
329+
});
333330
}
334331

335332
/**
@@ -345,13 +342,14 @@
345342
*/
346343
function getRoutes(dir, files = []) {
347344
fs.readdirSync(dir).forEach(function(file) {
348-
const filePath = path.join(dir, file); // nosemgrep
345+
const filePath = path.join(dir, file);
349346

350347
if (fs.lstatSync(filePath).isDirectory()) {
351348

352349
// Perform recursive traversal.
353350
getRoutes(filePath, files);
354-
} else if (path.extname(filePath) === '.js') {
351+
352+
} else /* istanbul ignore next */ if (path.extname(filePath) === '.js') {
355353
files.push(filePath);
356354
}
357355
});

RouterRequest.html

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

global.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

router_Request.js.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,17 @@
9999
param(name) {
100100
let obj = {};
101101

102-
/* istanbul ignore else (tested in: test/unit/Request) */
103102
if (this.queryString()) {
104103
obj = RouterRequest.parseParams(this.queryString());
105104
} else if (this.body()) {
106105
obj = RouterRequest.parseBody(this.body());
107106
}
108107

109-
if (name && obj[name]) {
110-
return obj[name];
111-
} else if (!name && obj) {
108+
if (Object.keys(obj).length > 0) {
109+
if (name) {
110+
return obj[name];
111+
}
112+
112113
return obj;
113114
}
114115
}
@@ -190,12 +191,12 @@
190191
const plugin = this.plugins[name];
191192

192193
if ((!plugin && name && value) || (plugin && value)) {
193-
this.plugins[name] = value;
194+
return this.plugins[name] = value;
194195
} else if (plugin && !value) {
195196
return this.plugins[name];
196-
} else if (!plugin) {
197-
throw new RouterError(`Plugin "${name}" doesn't exist`);
198197
}
198+
199+
throw new RouterError(`Plugin "${name}" doesn't exist`);
199200
}
200201

201202
/**

router_Route.js.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@
6262

6363
// Add route-bound middleware, if available.
6464
if (route.middleware) {
65-
66-
/* istanbul ignore else (tested in: test/e2e) */
6765
if (Array.isArray(route.middleware)) {
6866
route.middleware.forEach(func => router.use(path, func));
6967
} else {

0 commit comments

Comments
 (0)