Middleware blueprint for srvem (pronounced "serve 'em", a super-fast and minimalist middleware-oriented TypeScript server framework for Node.js).
npm install --save @srvem/middleware
srv-sample-middleware.ts:
import { SrvMiddleware } from '@srvem/middleware'
export class SampleMiddleware extends SrvMiddleware {
// `this.request: SrvRequest` is available
// `this.response: SrvResponse` is available
// you can use the constructor to accept parameters
constructor(private sampleParam: String) {
super()
}
// override
main(): void {
// middleware code starts handling requests here
}
}
main.ts:
import { Srvem } from '@srvem/app'
import { SrvSampleMiddleware} from './srv-sample-middleware'
const app: Srvem = new Srvem()
app.use(new SrvSampleMiddleware('sample string param'))
// more srvem middlewares can go here using app.use()
// handlers can also be defined here using app.handle()
app.start().listen()
interface SrvRequest extends IncomingMessage {} // the super class is from the built-in 'http' module
interface SrvResponse extends ServerResponse {} // the super class is from the built-in 'http' module
abstract class SrvMiddleware {
request: SrvRequest
response: SrvResponse
abstract main(): void
}
- @srvem/app a super-fast and minimalist TypeScript middleware-oriented server for Node.js.
- @srvem/static to serve static files from a specified directory.
- @srvem/router to develop routers and server APIs with asynchronous request handlers.
Kaleab S. Melkie (kaleabmelkie@gmail.com)
MIT License
Copyright © 2017 srvem
Made with ❤ in Addis Ababa.