请问eggjs的router怎么配置大小写不敏感?
发布于 6 年前 作者 chuanzai 4086 次浏览 来自 问答

目前默认是敏感大小写,怎么配置为不敏感呢?

4 回复

不能设置吗?有人知道吗?

@chuanzai 自己加个中间件啊!或者加个插件,将请求的path转成小写,router定义小写就可以了

来自酷炫的 CNodeMD

module.exports = app => {
  const { router, controller } = app;
  router.opts.sensitive = false;
  router.get('/ABC', controller.home.index);
};


it('should GET /', () => {
  return app.httpRequest()
    .get('/Abc')
    .expect('hi, egg')
    .expect(200);
});

https://github.com/eggjs/egg-core/blob/master/lib/egg.js#L317

没有什么问题是看源码解决不了的,如果有,就多看一个库。

(下一位~

thanks

回到顶部