@junaid1460/hapiest
v1.0.13
Published
Decorators for hapi 17+
Downloads
5
Readme
[Hapiest] Beautiful code is what I seek.
npm i @junaid1460/hapiest
Requirements
hapi 17+ typescript 3 (es6)
Usage
import { Request, ResponseToolkit, Server } from "hapi";
import { AbstractHapiModule, Decorators as d, HapiServerRoutes } from "@junaid1460/hapiest";
@d.routeGroup({ baseUrl: "api", auth: false })
export class AdminRoutes extends HapiServerRoutes {
@d.get({path: ""}) // Path: /api
api(request: Request, toolkit: ResponseToolkit, err?: Error) {
return "base\n"
}
@d.get() // Path: /api/getTest
public getTest(request: Request, toolkit: ResponseToolkit, err?: Error) {
return "hey, what's up?\n";
}
@d.get({path: 'name'}) // Path: /api/name
public async getit(request: Request, toolkit: ResponseToolkit, err?: Error) {
return "junaid\n";
}
}
class ArenaMainModule extends AbstractHapiModule {
public routeSets = [AdminRoutes];
public baseUrl = "dev";
}
export const hapiServer = new Server({
host: '0',
port: 8000,
routes: { cors: true },
});
async function start() {
await hapiServer.route(new ArenaMainModule().getRoutes())
await hapiServer.start().then(e => {
console.log("server started", hapiServer.table())
})
}
start()