Typescript decorators for Hapi
npm install --save hapi
npm install --save hapiour
src/
-> main.ts
-> app.ts
-> beer.module.ts
import {Server} from 'hapi'
import {App, IApp, Modules} from 'hapiour'
import {Beer} from './beer.module'
@App({
port: 3000
})
@Modules([Beer])
export class MyApp implements IApp {
private server: Server
public constructor(server: Server) {
this.server = server
}
public onInit(): void {
}
public onStart(): void {
console.log('Server running at:', this.server.info.uri)
}
}
import {Route, Modules, Module} from 'hapiour'
import {Request, IReply} from 'hapi'
@Module({
basePath: '/beer'
})
export class Beer {
public constructor() {}
@Route({
method: 'GET',
path: '',
config: {}
})
public get(request: Request, reply: IReply) {
reply({
'data': 'Hey I\'m alive'
})
}
}
import {bootstrap} from 'hapiour'
import {MyApp} from './app'
bootstrap(MyApp)
@App(config: Hapi.IServerConnectionOptions)
: Declare a new App (correspond to a new Hapi.Server instance).@Module(config: IModuleConfig)
: Declare a new Module (class containing routes).@Modules(modules: Array<Module>)
: Assign an array of modules to an App or a Module.
@Route(config: Hapi.IRouteConfiguration)
: Declare a new Route inside a Module. The target method will become the route handler.
constructor(server: Hapi.Server)
: App will be constructed with Hapi server instance as first argument.onInit()
: Method called when Hapi server initialization is done.onStart()
: Method called when Hapi server is started.
basePath: string
: Base path applied to all contained routes in the module.
bootstrap(...apps: Array<IApp>)
: Bootstrap your apps.