0.2.2 • Published 7 years ago

@srvem/middleware v0.2.2

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

@srvem/middleware

Middleware blueprint for srvem (pronounced \"serve 'em\", a super-fast and minimalist middleware-oriented TypeScript server framework for Node.js).

Installation

npm install --save @srvem/middleware

Usage

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()

Public API

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
}

See Also

  • @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.

Credits

Kaleab S. Melkie (kaleabmelkie@gmail.com)

License

MIT License
Copyright © 2017 srvem

Made with in Addis Ababa.

0.2.2

7 years ago

0.2.1

7 years ago

0.1.0

7 years ago

0.0.0

7 years ago