valley-router
router for valley-module
Last updated 2 years ago by hitvalley .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install valley-router 
SYNC missed versions from official npm registry.

valley-router

router for valley-module

run demo

npm i valley-router
npm run demo

服务器端运行

引入

npm i valley-router
npm i valley-server

代码

const ValleyServer = require('valley-server');
const ValleyRouter = require('valley-router');

const server = new ValleyServer();

const router = new ValleyRouter();
router.add('/info/:id', async function() {
  this.context.text('<div>' + (
    () => [
      this.context.path,
      this.context.method,
      JSON.stringify(this.context.params)
    ].join(' - ')
  )() + '</div>');
});

server.use('router', router);
server.use('404', async function(next){
  this.context.text('404');
  await next();
});

server.listen({
  port: 3000
}).then(res => console.log('http://localhost:3000'));

结果

  1. 访问 http://localhost:3000/info/1 得到页面
  2. 访问其他页面会得到 404

Current Tags

  • 1.0.11                                ...           latest (2 years ago)

12 Versions

  • 1.0.11                                ...           2 years ago
  • 1.0.10                                ...           2 years ago
  • 1.0.9                                ...           2 years ago
  • 1.0.8                                ...           2 years ago
  • 1.0.7                                ...           2 years ago
  • 1.0.6                                ...           2 years ago
  • 1.0.5                                ...           2 years ago
  • 1.0.4                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 2
Last Month 4
Dependencies (9)
Dev Dependencies (0)
None
Dependents (1)

Copyright 2014 - 2016 © taobao.org |