rauter
v0.1.4
Published
An experimental JS router for any HTTP server based on the HTTP module from Node.js
Downloads
16
Readme
Rauter
Rauter is an experimental router library written in Typescript, for any framework based in the Node.js's HTTP library, comes with a params parser by default.
I've built this as a workaround for handling nested routes inside firebase functions.
Installation
With npm:
$ npm i rauter
With yarn:
$ yarn add rauter
Example
With HTTP from Node.js
const http = require('http')
const Rauter = require('rauter')
const port = 3000
const router = new Rauter('url not found')
router.get('/', (req, res) => {
res.end('hello')
})
router.get('/hello/:name', (req, res) => {
res.end(`hello ${req.params.id}`)
})
const requestHandler = (request, response) => {
Rauter.use(router, request, response)
}
const server = http.createServer(requestHandler)
server.listen(port, err => {
if (err) {
return console.log('something bad happened', err)
}
console.log(`server is listening on ${port}`)
})
With Firebase Cloud Functions
const functions = require('firebase-functions')
const Rauter = require('rauter')
const router = new Rauter()
router.get('/', (req, res) => {
res.send('hello world')
})
router.get('/greetings/:name', (req, res) => {
res.send(`hello ${req.params.name}`)
})
exports.functionName = functions.https.onRequest((req, res) => {
Rauter.use(router, req, res)
})
TODO
- [ ] Write tests
- [ ] Make a middleware interface
- [ ] Use with app.use in koa, express and similar.