1.1.3 • Published 4 years ago

kenote-express-helper v1.1.3

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

express-helper

Express's Helper.

NPM Version NPM Downloads Build Status Gratipay

Installation

$ npm install kenote-express-helper
# Or
$ yarn add kenote-express-helper

Usages

controller/account.ts

import { Request, Response, NextFunction } from 'express'
import { Controller, Path, Router, Filter } from 'kenote-express-helper'
import accountFilter from '../filters/account'
import { IResponse } from '../middleware/restful'

@Path('/account')
export default class Account extends Controller {

  @Router({ method: 'get', path: '/home' })
  public home (req: Request, res: Response, next: NextFunction): Response {
    return res.json({ test: 'ok' })
  }

  @Router({ method: 'post', path: '/login' })
  @Filter(accountFilter.login)
  public login (document: any, req: Request, res: IResponse, next: NextFunction): Response {
    return res.api(document)
  }

  @Router({ method: 'get', path: '/help' })
  public help (req: Request, res: IResponse, next: NextFunction): void {
    return res.notfound()
  }
}

controller/index.ts

import { MountController } from 'kenote-express-helper'
import Account from './account'

export default MountController( Account )

filters/account.ts

import { Request, Response, NextFunction } from 'express'

class Account {

  public login (req: Request, res: Response, next: NextFunction): Response | void {
    return next({ test: 'ok' })
  }
}

export default new Account()

app.ts

import * as http from 'http'
import * as express from 'express'
import { Application } from 'express'
import { mountPipeline } from 'kenote-express-helper'
import restful from './middleware/restful'
import controller from './controller'

const app: Application = express()
app.use(restful)

// Auto Routing
mountPipeline('/api/v1', 'controller', app, { root: 'src' })

// Manual Routing
app.use('/api/v2', controller)

http.createServer(app).listen(3000)

License

this repo is released under the MIT License.

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago