Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.
/ middleware Public archive

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

License

Notifications You must be signed in to change notification settings

srvem/middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published