A light-weight, promise-based, middleware-driven and express-compatible web framework
Features
- Use promise-based middlewares(support async/await)
- Better error handle(see Error Handle)
- Easily use express middlewares(see Migrate From Express)
- The core is light-weight, all functionalities are driven by midd-* middlewares, like
midd-router
,midd-static
- Support request forward:
req.forward('/new/url')
Example
const middServer = ;const app = ; appappapp
API
middServer()
Create an app server.
app.use(...middlewares)
Attach middlewares. A middleware is a function like (req, resp, next)=>Promise
.
app.listen()
Same as node server.listen()
function.
app.on('error', cb:(err, resp)=>void)
Catch uncaught error in middlewares
req.forward(url)
Forward the request to another url.
app.listener()
Used like http.createServer(app.listerner())
Middlewares
- midd-router: Router that support
use()
,get()
,post()
etc - midd-static: Serve static files
- midd-session: Session middleware
- midd-send: Send methods middleware
- midd-cache: HTTP cache middleware
- midd-url: Expose
req.url
object attributes inreq
, likehost
,port
- midd-header: HTTP header middleware
- midd-ip: IP middleware
Error Handle
You can use app.on('error', cb)
to catch the uncaught error, or try/catch
with async/await
in middlewares
Migrate From Express
Currently only support express middleware operations, like express.Router
and express.use|all|get|post|...()
appexpressappexpressappexpress
Contributing
Checkout the CONTRIBUTING.md if you want to help
License
Licensed under MIT
Copyright (c) 2017 Tian Jian