JSPM

@rxdi/hapi

0.0.10
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 27
  • Score
    100M100P100Q100263F
  • License MIT

Package Exports

  • @rxdi/hapi

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rxdi/hapi) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@rxdi Hapi Module

More information about Hapi server can be found here Hapi
For questions/issues you can write ticket here
This module is intended to be used with rxdi

Installation and basic examples:

To install this Gapi module, run:
$ npm install @rxdi/hapi --save

Consuming @rxdi/hapi

Import inside AppModule or CoreModule
import { Module } from "@rxdi/core";
import { HapiModule } from "@rxdi/hapi";

@Module({
    imports: [
        HapiModule.forRoot({
            hapi: {
                port: 9000
            }
        })
    ]
})
export class CoreModule {}

Create Hapi plugin Note: To use it plugin needs to be imported inside plugins otherwise can be @Service read down


import { PluginInterface, Inject, Module, Plugin } from '@rxdi/core';
import { UserService } from './services';
import { HAPI_SERVER } from '@rxdi/hapi';
import { Server } from 'hapi';

@Plugin()
export class TestHapiService implements PluginInterface {

    constructor(
        @Inject(HAPI_SERVER) private server: Server
    ) {}

    async register() {
        this.server.route({
            method: 'GET',
            path: '/test',
            handler: this.handler.bind(this)
        });
    }

    async handler(request, h) {
        return 'dadda2';
    }

}

@Module({
    plugins: [TestHapiService],
})
export class UserModule { }

If you don't want to import it like a plugin you can set it as a @Service and import it inside services One downside is that you need to trigger register() method on constructor initialization like so because you will not get your route added to hapi.

import { PluginInterface, Inject, Service, Module } from '@rxdi/core';
import { HAPI_SERVER } from '@rxdi/hapi';
import { Server } from 'hapi';

@Service()
export class TestHapiService implements PluginInterface {

    constructor(
        @Inject(HAPI_SERVER) private server: Server
    ) {
        this.register();
    }

    async register() {
        this.server.route({
            method: 'GET',
            path: '/test',
            handler: this.handler.bind(this)
        });
    }

    async handler(request, h) {
        return 'dada1';
    }

}

@Module({
    services: [TestHapiService]
})
export class UserModule { }

TODO: Better documentation...

Enjoy ! :)