a Node.js web framework
Weekly downloads
Readme
English | 简体中文
Urgot is a Nodejs HTTP middleware framework written in Typescript. It allows you to create and pass down requests in the middleware, then filter and respond in reverse order. It comes with an out-of-the-box application development framework, hot update, Session, etc. It supports both Javascript and Typescript.
$ npm install urgot
//index.js
import { Server } from "urgot"
const server = new Server()
server.use(async (context, next) => {
context.body = "Hello World"
await next()
})
server.run(8080)
Middleware is the main function of urgot. Calling the use
method to register a middleware requires an asynchronous function (Promise) as a parameter.
server.use(async (context, next) => {
const start = Date.now()
await next()
const ms = Date.now() - start
context.setHeader("X-Response-Time", `${ms}ms`)
context.body = "Hello World"
})
Tips: Whenever you should call await next() to let the downstream intermediate response execution.
Each middleware will receive a Context object and a next
asynchronous function. The Context
object is the encapsulation of Http.ServerResponse
, of course you can visit context.response
to access it, but usually we do not recommend it. After processing the middleware, you need to call the next
function to let the downstream middleware Respond to execution.
https://gitee.com/apprat/urgot-server