Skip to content

Commit 86821e7

Browse files
authored
Performance optimization (#30)
* optimizing recurrent statements * adding demo which uses no router cache
1 parent 5f895c6 commit 86821e7

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

demos/basic-nocache.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const cero = require('../index')
2+
const { router, server } = cero({
3+
router: require('../lib/router/sequential')({
4+
cacheSize: 0
5+
})
6+
})
7+
8+
router.get('/hi', (req, res) => {
9+
res.end('Hello!')
10+
})
11+
12+
server.listen(3000)

lib/next.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ function next (middlewares, req, res, index, routers = {}, defaultRoute, errorHa
2525
req.preRouterPath = req.path
2626

2727
req.url = req.url.replace(pattern, '')
28-
if (!req.url.startsWith('/')) {
29-
req.url = '/' + req.url
28+
if (req.url.charCodeAt(0) !== 47) {
29+
req.url = '\u002f'.concat(req.url)
3030
}
3131
}
3232

0 commit comments

Comments
 (0)