2.0.5 • Published 6 years ago

3h-router v2.0.5

Weekly downloads
35
License
MIT
Repository
github
Last release
6 years ago

3h-router

A simple router lib.

Features

  • Gzip/Deflate support
  • Main router and sub-routers

Example

main router

const Router = require('3h-router'),
    router = new Router({ basePath: __dirname });

// You can get default values via Router.defaultOptions.
router.defaultPages.unshift('my-default-page.html');
router.subRouters.unshift('my-sub-router.js');

router.on('before', url => {
    console.log(`[before] ${url}`);
    // If there's any `before` event handler, then
    // the routing will pause here, so remember to
    // call router.route to continue the routing.
    // In addition, if you want to forward the
    // request, then just pass the target url.
    router.route(url);
}).on('result', result => {
    console.log(`[result] ${result.code}`);
}).on('error', err => {
    console.log('An error occurred!');
    console.error(err);
}).start(88);

console.log('Server started on port 88!');

sub-router

module.exports = router => {
    const { response } = router;
    response.writeHead(200, {
        'Content-Type': 'text/html'
    });
    response.end('<h1>Generated by sub-router!</h1>');
};

APIs

Just read the declaration files in typings to learn the APIs.

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

1.8.1

6 years ago

1.8.0

6 years ago

1.7.0

6 years ago

1.6.0

6 years ago

1.5.3

6 years ago

1.5.2

6 years ago

1.5.1

6 years ago

1.5.0

6 years ago

1.4.2

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.2

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago