Git Product home page Git Product logo

koa-rapid-router's Introduction

About

Email: [email protected]

15年前端开发经验,曾任51信用卡前端负责人,51信用卡nodejs布道者。Miox 开源架构创始人,专注前端全栈领域。

Evio's Top Langs

Organizations And Repositories

  • Miox: Modern infrastructure of complex SPA for 51 credit company.
  • Private Npm Registry: power npm private registry for company.
  • Dubbo - Provider & Consumer: Nodejs implementation of high performance Dubbo protocol
  • FlowX Team Create TypeService as Node Development And TypeClient as Web Development frameworks.
    • TypeService: It is a set of lightweight and high-performance container service architecture, which mainly solves the problem of single process and multiple services.
    • TypeClient: TypeClient is a set of lightweight and high-performance SPA routing management and maintenance architecture, which mainly solves the pain points of project development based on IOC mode. It can flexibly connect Vue or React through the driver mode, allowing users to get a better development experience.

Summary

Evio's github stats

koa-rapid-router's People

Contributors

cevio avatar mitscherlich avatar zlgwangjunsheng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

koa-rapid-router's Issues

Windows 系统下不能正常工作,路由路径无法命中

路由路径无法命中。
Windows 10
NodeJS: v14.15.4
将源代码注释后修改如下才能运行,应该是Windows 系统下的path.resolve() 方法返回的是win文件系统的路径。
源文件路径:node_modules\koa-rapid-router\lib\router.js 33:3
修改之前:

Router.prototype[VERB] = function(method, router, ...callbacks) {

  router = router.startsWith('/')
    ? path.resolve(this[PREFIX], '.' + router) 
    : path.resolve(this[PREFIX], router);

修改之后:

Router.prototype[VERB] = function(method, router, ...callbacks) {

  router = router.startsWith('/')
    ? this[PREFIX] + router 
    : this[PREFIX] + '/' + router;

TypeError: Cannot read property '__MIDDLEWARES__' of undefined

Error: GET / 500 TypeError: Cannot read property 'MIDDLEWARES' of undefined
at Server.find (node_modules/koa-rapid-router/lib/server.js:41:36)
at Koa (node_modules/koa-rapid-router/lib/server.js:26:44)
at dispatch (node_modules/koa-compose/index.js:42:32)
at cors (node_modules/kcors/index.js:53:14)
at dispatch (node_modules/koa-compose/index.js:42:32)
at dispatch (node_modules/koa-compose/index.js:42:32)
at bodyParser (node_modules/koa-bodyparser/index.js:86:11)
at process.internalTickCallback (internal/process/next_tick.js:77:7)

Issue with multi params

Set this route:
router.get('/g/{repo:string}/{filePath?:any}', (ctx) => ..)

Then view
http://127.0.0.1:8080/g/xxxxxx/index.html

Got error:

TypeError: Cannot read property 'index.html' of undefined
      at Server.[Server#find_children] (...node_modules/koa-rapid-router/lib/server.js:74:15)
      at Server.[Server#find_children] (...node_modules/koa-rapid-router/lib/server.js:123:37)
      at Server.[Server#find_children] (...node_modules/koa-rapid-router/lib/server.js:78:33)
      at Server.find (...node_modules/koa-rapid-router/lib/server.js:56:24)
      at Koa (...node_modules/koa-rapid-router/lib/server.js:30:44)
      at dispatch (...node_modules/koa-compose/index.js:42:32)
      at ...node_modules/koa-compress/index.js:38:11
      at dispatch (...node_modules/koa-compose/index.js:42:32)

At koa-rapid-router/lib/server.js:122 print r, l, regexp, target, reg, _params got:
index.html
524ba4a9
{repo:string}

{ __REGEXPS__: [ '{repo:string}' ],
  __MIDDLEWARES__: [],
  __CACHES__: Map {},
  '{repo:string}':
   { __REGEXPS__: [ '{filePath?:any}' ],
     __MIDDLEWARES__: [],
     __CACHES__: Map {},
     '{filePath?:any}':
      { __REGEXPS__: [], __MIDDLEWARES__: [Array], __CACHES__: Map {} } } } StringToRegExp {
  string: '{repo:string}',
  match_regexp: /^([a-zA-Z0-9]+)$/,
  exec_regexp: /^(.+?)$/,
  params: { repo: { index: 1, regexp: 'string', ignore: false } },
  greedy: false,
  expressions: { any: '.+', string: '[a-zA-Z0-9]+', number: '\\d+' } } 

{ repo: '524ba4a9' }

So it should be call target[regexp] instead of target[l]

用了这一段代码访问localhost:3000没有输出Hello world啊

const Koa = require('koa');
const Router = require('koa-rapid-router')
// 创建服务对象容器
const app = new Koa();
const routerContianer = new Router();
// 生成路由对象
const router = routerContianer.create(/prefix: default '/'/);
// 注入中间件
router.use(async (ctx, next) => {
console.log(ctx.path);
await next();
});
// 注入路由
router.get('/', async ctx => ctx.body = 'Hello world!');
// 链接中间件到KOA
app.use(routerContianer.Koa());
// 启动服务
app.listen(3000, err => {
if (err) throw err;
console.log('Server run at 3000');
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.