Skip to content

Instantly share code, notes, and snippets.

@vincenting
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save vincenting/d0337252bb8912467090 to your computer and use it in GitHub Desktop.

Select an option

Save vincenting/d0337252bb8912467090 to your computer and use it in GitHub Desktop.
var express = require('express');
var app = express();
var router = express.Router();
router.get('/', function (req, res) {
res.send('hello world');
});
router.get('/reset', function (req, res) {
var router_stack = router.stack.concat([]);
router.stack.length = 0;
router_stack.forEach(function (item) {
if (item.route.path !== '/') {
router.stack.push(item);
}
});
res.send('ok');
});
process.on('SIGTERM', function() {
console.log('Controller will be reload');
});
app.use(router);
app.listen(3000);
@RenderCoder
Copy link

问一个小白问题,router.stack 明明是数组,为什么还要.concat([])呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment