| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -81,7 +81,6 @@ | |||
| 81 | 81 | ||
| 82 | 82 | const result = this.stack.exec(this.req, this.res); | |
| 83 | 83 | ||
| 84 | - /* istanbul ignore if (tested in: test/e2e/async) */ | ||
| 85 | 84 | if (isPromise(result)) { | |
| 86 | 85 | return result.then(() => this.res.data()); | |
| 87 | 86 | } | |
@@ -313,23 +312,21 @@ | |||
| 313 | 312 | function loadRoutes(router) { | |
| 314 | 313 | const routeDir = moduleParent() + '/routes'; | |
| 315 | 314 | ||
| 316 | - if (fs.existsSync(routeDir)) { | ||
| 317 | - const files = getRoutes(routeDir); | ||
| 315 | + const files = getRoutes(routeDir); | ||
| 318 | 316 | ||
| 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); | ||
| 322 | 320 | ||
| 323 | - const filePath = [dir, name].join('/'); | ||
| 324 | - const route = require(`${routeDir}/${filePath}`); | ||
| 321 | + const filePath = [dir, name].join('/'); | ||
| 322 | + const route = require(`${routeDir}/${filePath}`); | ||
| 325 | 323 | ||
| 326 | - route.path = ( | ||
| 327 | - filePath[0] === '/' ? filePath : `/${filePath}` | ||
| 328 | - ).toLowerCase(); | ||
| 324 | + route.path = ( | ||
| 325 | + filePath[0] === '/' ? filePath : `/${filePath}` | ||
| 326 | + ).toLowerCase(); | ||
| 329 | 327 | ||
| 330 | - Route(router, route); | ||
| 331 | - }); | ||
| 332 | - } | ||
| 328 | + Route(router, route); | ||
| 329 | + }); | ||
| 333 | 330 | } | |
| 334 | 331 | ||
| 335 | 332 | /** | |
@@ -345,13 +342,14 @@ | |||
| 345 | 342 | */ | |
| 346 | 343 | function getRoutes(dir, files = []) { | |
| 347 | 344 | fs.readdirSync(dir).forEach(function(file) { | |
| 348 | - const filePath = path.join(dir, file); // nosemgrep | ||
| 345 | + const filePath = path.join(dir, file); | ||
| 349 | 346 | ||
| 350 | 347 | if (fs.lstatSync(filePath).isDirectory()) { | |
| 351 | 348 | ||
| 352 | 349 | // Perform recursive traversal. | |
| 353 | 350 | getRoutes(filePath, files); | |
| 354 | - } else if (path.extname(filePath) === '.js') { | ||
| 351 | + | ||
| 352 | + } else /* istanbul ignore next */ if (path.extname(filePath) === '.js') { | ||
| 355 | 353 | files.push(filePath); | |
| 356 | 354 | } | |
| 357 | 355 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -99,16 +99,17 @@ | |||
| 99 | 99 | param(name) { | |
| 100 | 100 | let obj = {}; | |
| 101 | 101 | ||
| 102 | - /* istanbul ignore else (tested in: test/unit/Request) */ | ||
| 103 | 102 | if (this.queryString()) { | |
| 104 | 103 | obj = RouterRequest.parseParams(this.queryString()); | |
| 105 | 104 | } else if (this.body()) { | |
| 106 | 105 | obj = RouterRequest.parseBody(this.body()); | |
| 107 | 106 | } | |
| 108 | 107 | ||
| 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 | + | ||
| 112 | 113 | return obj; | |
| 113 | 114 | } | |
| 114 | 115 | } | |
@@ -190,12 +191,12 @@ | |||
| 190 | 191 | const plugin = this.plugins[name]; | |
| 191 | 192 | ||
| 192 | 193 | if ((!plugin && name && value) || (plugin && value)) { | |
| 193 | - this.plugins[name] = value; | ||
| 194 | + return this.plugins[name] = value; | ||
| 194 | 195 | } else if (plugin && !value) { | |
| 195 | 196 | return this.plugins[name]; | |
| 196 | - } else if (!plugin) { | ||
| 197 | - throw new RouterError(`Plugin "${name}" doesn't exist`); | ||
| 198 | 197 | } | |
| 198 | + | ||
| 199 | + throw new RouterError(`Plugin "${name}" doesn't exist`); | ||
| 199 | 200 | } | |
| 200 | 201 | ||
| 201 | 202 | /** | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,8 +62,6 @@ | |||
| 62 | 62 | ||
| 63 | 63 | // Add route-bound middleware, if available. | |
| 64 | 64 | if (route.middleware) { | |
| 65 | - | ||
| 66 | - /* istanbul ignore else (tested in: test/e2e) */ | ||
| 67 | 65 | if (Array.isArray(route.middleware)) { | |
| 68 | 66 | route.middleware.forEach(func => router.use(path, func)); | |
| 69 | 67 | } else { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments