@rxdi/hapi 0.7.118

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # @rxdi Hapi Module
2
+
3
+ ##### More information about Hapi server can be found here [Hapi](https://hapijs.com/)
4
+ ##### For questions/issues you can write ticket [here](http://gitlab.youvolio.com/rxdi/hapi/issues)
5
+ ##### This module is intended to be used with [rxdi](https://github.com/rxdi/core)
6
+
7
+ ## Installation and basic examples:
8
+ ##### To install this Gapi module, run:
9
+
10
+ ```bash
11
+ $ npm install @rxdi/hapi --save
12
+ ```
13
+
14
+ ## Consuming @rxdi/hapi
15
+
16
+ ##### Import inside AppModule or CoreModule
17
+ ```typescript
18
+ import { Module } from "@rxdi/core";
19
+ import { HapiModule } from "@rxdi/hapi";
20
+
21
+ @Module({
22
+ imports: [
23
+ HapiModule.forRoot({
24
+ hapi: {
25
+ port: 9000
26
+ }
27
+ })
28
+ ]
29
+ })
30
+ export class CoreModule {}
31
+ ```
32
+
33
+ Create Hapi plugin
34
+ Note: To use it plugin needs to be imported inside `plugins` otherwise can be @Service read down
35
+
36
+ ```typescript
37
+
38
+
39
+ import { PluginInterface, Inject, Module, Plugin } from '@rxdi/core';
40
+ import { UserService } from './services';
41
+ import { HAPI_SERVER } from '@rxdi/hapi';
42
+ import { Server } from 'hapi';
43
+
44
+ @Plugin()
45
+ export class TestHapiService implements PluginInterface {
46
+
47
+ constructor(
48
+ @Inject(HAPI_SERVER) private server: Server
49
+ ) {}
50
+
51
+ async register() {
52
+ this.server.route({
53
+ method: 'GET',
54
+ path: '/test',
55
+ handler: this.handler.bind(this)
56
+ });
57
+ }
58
+
59
+ async handler(request, h) {
60
+ return 'dadda2';
61
+ }
62
+
63
+ }
64
+
65
+ @Module({
66
+ plugins: [TestHapiService],
67
+ })
68
+ export class UserModule { }
69
+ ```
70
+
71
+ If you don't want to import it like a plugin you can set it as a @Service and import it inside `services`
72
+ 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.
73
+
74
+ ```typescript
75
+ import { PluginInterface, Inject, Service, Module } from '@rxdi/core';
76
+ import { HAPI_SERVER } from '@rxdi/hapi';
77
+ import { Server } from 'hapi';
78
+
79
+ @Service()
80
+ export class TestHapiService implements PluginInterface {
81
+
82
+ constructor(
83
+ @Inject(HAPI_SERVER) private server: Server
84
+ ) {
85
+ this.register();
86
+ }
87
+
88
+ async register() {
89
+ this.server.route({
90
+ method: 'GET',
91
+ path: '/test',
92
+ handler: this.handler.bind(this)
93
+ });
94
+ }
95
+
96
+ async handler(request, h) {
97
+ return 'dada1';
98
+ }
99
+
100
+ }
101
+
102
+ @Module({
103
+ services: [TestHapiService]
104
+ })
105
+ export class UserModule { }
106
+ ```
107
+
108
+
109
+ TODO: Better documentation...
110
+
111
+ Enjoy ! :)
@@ -0,0 +1,15 @@
1
+ import { InjectionToken } from "@rxdi/core";
2
+ import { PluginNameVersion, PluginBase, PluginPackage, ServerOptions, ServerRoute } from 'hapi';
3
+ export declare class HapiConfigModel {
4
+ randomPort?: boolean;
5
+ staticConfig?: ServerRoute | ServerRoute[];
6
+ hapi?: ServerOptions;
7
+ plugins?: Array<PluginBase<any> & (PluginNameVersion | PluginPackage)>;
8
+ }
9
+ export declare const HAPI_CONFIG: InjectionToken<HapiConfigModel>;
10
+ export declare const HAPI_SERVER: InjectionToken<any>;
11
+ export declare const HAPI_PLUGINS: InjectionToken<((PluginBase<any> & PluginNameVersion) | (PluginBase<any> & PluginPackage))[]>;
12
+ export declare const Route: ({ method, path }: {
13
+ path: string;
14
+ method: string;
15
+ }) => (target: unknown, key: string, descriptor: PropertyDescriptor) => void;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Route = exports.HAPI_PLUGINS = exports.HAPI_SERVER = exports.HAPI_CONFIG = exports.HapiConfigModel = void 0;
4
+ const core_1 = require("@rxdi/core");
5
+ class HapiConfigModel {
6
+ constructor() {
7
+ this.staticConfig = {
8
+ method: 'GET',
9
+ path: '/public/{param*}',
10
+ handler: {
11
+ directory: {
12
+ path: 'public',
13
+ index: ['index.html', 'default.html']
14
+ }
15
+ }
16
+ };
17
+ }
18
+ }
19
+ exports.HapiConfigModel = HapiConfigModel;
20
+ exports.HAPI_CONFIG = new core_1.InjectionToken('hapi-config-injection-token');
21
+ exports.HAPI_SERVER = new core_1.InjectionToken('hapi-server-injection-token');
22
+ exports.HAPI_PLUGINS = new core_1.InjectionToken('hapi-plugins-injection-token');
23
+ exports.Route = ({ method, path }) => (target, key, descriptor) => {
24
+ const handler = descriptor.value.bind(target);
25
+ descriptor.value = function (...args) {
26
+ return handler(...args);
27
+ };
28
+ core_1.Container.get(exports.HAPI_SERVER).route({
29
+ method,
30
+ path,
31
+ handler: (r, h) => descriptor.value(r, h),
32
+ });
33
+ };
package/dist/main.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { ModuleWithServices } from '@rxdi/core';
2
+ import { HapiConfigModel } from './hapi.module.config';
3
+ export declare class HapiModule {
4
+ static forRoot(config?: HapiConfigModel): ModuleWithServices;
5
+ }
6
+ export * from './hapi.module.config';
7
+ export * from './plugins/index';
8
+ export * from './services/index';
package/dist/main.js ADDED
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
10
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
11
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
12
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
13
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
14
+ };
15
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
17
+ };
18
+ var HapiModule_1;
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.HapiModule = void 0;
21
+ const hapi_1 = require("hapi");
22
+ const hapi_plugin_1 = require("./plugins/hapi.plugin");
23
+ const server_service_1 = require("./services/server/server.service");
24
+ const core_1 = require("@rxdi/core");
25
+ const hapi_module_config_1 = require("./hapi.module.config");
26
+ const inert_plugin_1 = require("./plugins/inert/inert.plugin");
27
+ const open_service_1 = require("./services/open/open.service");
28
+ let HapiModule = HapiModule_1 = class HapiModule {
29
+ static forRoot(config) {
30
+ config = Object.assign({}, config || new hapi_module_config_1.HapiConfigModel());
31
+ config.randomPort && config.hapi.port ? config.hapi.port = null : null;
32
+ return {
33
+ module: HapiModule_1,
34
+ providers: [
35
+ {
36
+ provide: hapi_module_config_1.HAPI_CONFIG,
37
+ useValue: config || new hapi_module_config_1.HapiConfigModel()
38
+ },
39
+ {
40
+ provide: hapi_module_config_1.HAPI_SERVER,
41
+ deps: [hapi_module_config_1.HAPI_CONFIG],
42
+ useFactory: (config) => {
43
+ delete config.plugins;
44
+ return new hapi_1.Server(config.hapi);
45
+ }
46
+ },
47
+ {
48
+ provide: hapi_module_config_1.HAPI_PLUGINS,
49
+ useValue: config.plugins || []
50
+ },
51
+ server_service_1.ServerService,
52
+ open_service_1.OpenService
53
+ ],
54
+ plugins: [hapi_plugin_1.HapiPlugin, inert_plugin_1.InertPlugin]
55
+ };
56
+ }
57
+ };
58
+ HapiModule = HapiModule_1 = __decorate([
59
+ core_1.Module({
60
+ services: [],
61
+ plugins: []
62
+ })
63
+ ], HapiModule);
64
+ exports.HapiModule = HapiModule;
65
+ __exportStar(require("./hapi.module.config"), exports);
66
+ __exportStar(require("./plugins/index"), exports);
67
+ __exportStar(require("./services/index"), exports);
@@ -0,0 +1,7 @@
1
+ import { PluginInterface } from "@rxdi/core";
2
+ import { ServerService } from "../services/server/server.service";
3
+ export declare class HapiPlugin implements PluginInterface {
4
+ private server;
5
+ constructor(server: ServerService);
6
+ register(): Promise<void>;
7
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
12
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
13
+ return new (P || (P = Promise))(function (resolve, reject) {
14
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
15
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
17
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
18
+ });
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.HapiPlugin = void 0;
22
+ const core_1 = require("@rxdi/core");
23
+ const server_service_1 = require("../services/server/server.service");
24
+ let HapiPlugin = class HapiPlugin {
25
+ constructor(server) {
26
+ this.server = server;
27
+ }
28
+ register() {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ return yield this.server.start();
31
+ });
32
+ }
33
+ };
34
+ HapiPlugin = __decorate([
35
+ core_1.Plugin(),
36
+ __metadata("design:paramtypes", [server_service_1.ServerService])
37
+ ], HapiPlugin);
38
+ exports.HapiPlugin = HapiPlugin;
@@ -0,0 +1,2 @@
1
+ export * from './hapi.plugin';
2
+ export * from './inert/inert.plugin';
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./hapi.plugin"), exports);
14
+ __exportStar(require("./inert/inert.plugin"), exports);
@@ -0,0 +1,10 @@
1
+ import { HapiConfigModel } from "../../hapi.module.config";
2
+ import { Server } from "hapi";
3
+ export declare class InertPlugin {
4
+ private server;
5
+ private config;
6
+ constructor(server: Server, config: HapiConfigModel);
7
+ OnInit(): void;
8
+ register(): Promise<void>;
9
+ registerInertPlugin(): Promise<void>;
10
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.InertPlugin = void 0;
25
+ const core_1 = require("@rxdi/core");
26
+ const hapi_module_config_1 = require("../../hapi.module.config");
27
+ const hapi_1 = require("hapi");
28
+ const inert = require("inert");
29
+ let InertPlugin = class InertPlugin {
30
+ constructor(server, config) {
31
+ this.server = server;
32
+ this.config = config;
33
+ }
34
+ OnInit() {
35
+ this.register();
36
+ }
37
+ register() {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ yield this.registerInertPlugin();
40
+ if (this.config.staticConfig) {
41
+ this.server.route(this.config.staticConfig);
42
+ }
43
+ });
44
+ }
45
+ registerInertPlugin() {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ yield this.server.register(inert);
48
+ });
49
+ }
50
+ };
51
+ InertPlugin = __decorate([
52
+ core_1.Plugin(),
53
+ __param(0, core_1.Inject(hapi_module_config_1.HAPI_SERVER)),
54
+ __param(1, core_1.Inject(hapi_module_config_1.HAPI_CONFIG)),
55
+ __metadata("design:paramtypes", [hapi_1.Server,
56
+ hapi_module_config_1.HapiConfigModel])
57
+ ], InertPlugin);
58
+ exports.InertPlugin = InertPlugin;
@@ -0,0 +1,2 @@
1
+ export * from './server/server.service';
2
+ export * from './open/open.service';
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./server/server.service"), exports);
14
+ __exportStar(require("./open/open.service"), exports);
@@ -0,0 +1,8 @@
1
+ import { Server } from "hapi";
2
+ export declare class OpenService {
3
+ private server;
4
+ constructor(server: Server);
5
+ openServerPage(): Promise<void>;
6
+ openGraphQLPage(): Promise<void>;
7
+ openPage(link: any): Promise<void>;
8
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.OpenService = void 0;
25
+ const core_1 = require("@rxdi/core");
26
+ const open = require("opn");
27
+ const hapi_module_config_1 = require("../../hapi.module.config");
28
+ const hapi_1 = require("hapi");
29
+ let OpenService = class OpenService {
30
+ constructor(server) {
31
+ this.server = server;
32
+ }
33
+ openServerPage() {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ yield open(`http://${this.server.info.address}:${this.server.info.port}/public`);
36
+ });
37
+ }
38
+ openGraphQLPage() {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ yield open(`http://${this.server.info.address}:${this.server.info.port}/graphiql`);
41
+ });
42
+ }
43
+ openPage(link) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ yield open(link);
46
+ });
47
+ }
48
+ };
49
+ OpenService = __decorate([
50
+ core_1.Service(),
51
+ __param(0, core_1.Inject(hapi_module_config_1.HAPI_SERVER)),
52
+ __metadata("design:paramtypes", [hapi_1.Server])
53
+ ], OpenService);
54
+ exports.OpenService = OpenService;
@@ -0,0 +1,12 @@
1
+ import { BootstrapLogger, ExitHandlerService } from "@rxdi/core";
2
+ import { Server, PluginBase, PluginNameVersion, PluginPackage } from "hapi";
3
+ export declare type PluginType<T> = (PluginBase<T> & (PluginNameVersion | PluginPackage))[];
4
+ export declare class ServerService {
5
+ private server;
6
+ private plugins;
7
+ private logger;
8
+ private exitHandler;
9
+ constructor(server: Server, plugins: PluginType<any>, logger: BootstrapLogger, exitHandler: ExitHandlerService);
10
+ start(): Promise<void>;
11
+ registerPlugins<T>(plugins: PluginType<T>): Promise<void[]>;
12
+ }
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.ServerService = void 0;
25
+ const core_1 = require("@rxdi/core");
26
+ const hapi_module_config_1 = require("../../hapi.module.config");
27
+ const hapi_1 = require("hapi");
28
+ let ServerService = class ServerService {
29
+ constructor(server, plugins, logger, exitHandler) {
30
+ this.server = server;
31
+ this.plugins = plugins;
32
+ this.logger = logger;
33
+ this.exitHandler = exitHandler;
34
+ this.exitHandler.errorHandler.subscribe(() => __awaiter(this, void 0, void 0, function* () { return yield this.server.stop(); }));
35
+ }
36
+ start() {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ if (this.plugins.length) {
39
+ yield this.registerPlugins(this.plugins);
40
+ }
41
+ try {
42
+ yield this.server.start();
43
+ }
44
+ catch (err) {
45
+ throw new Error(err);
46
+ }
47
+ this.logger.log(`
48
+ Server running at: http://${this.server.info.address}:${this.server.info.port},
49
+ Environment: ${process.env.NODE_ENV || 'development'}
50
+ `);
51
+ });
52
+ }
53
+ registerPlugins(plugins) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ return yield Promise.all(plugins.map((p) => __awaiter(this, void 0, void 0, function* () { return yield this.server.register(p); })));
56
+ });
57
+ }
58
+ };
59
+ ServerService = __decorate([
60
+ core_1.Service(),
61
+ __param(0, core_1.Inject(hapi_module_config_1.HAPI_SERVER)),
62
+ __param(1, core_1.Inject(hapi_module_config_1.HAPI_PLUGINS)),
63
+ __metadata("design:paramtypes", [hapi_1.Server, Array, core_1.BootstrapLogger,
64
+ core_1.ExitHandlerService])
65
+ ], ServerService);
66
+ exports.ServerService = ServerService;
@@ -0,0 +1,15 @@
1
+
2
+ commands:
3
+ testing:
4
+ browser: jest --env jsdom --testPathPattern="/src/.*\\.browser.spec.(ts|tsx|js)$"
5
+ node: jest --env node --testPathPattern="/src/.*\\.spec.(ts|tsx|js)$"
6
+ build:
7
+ core:
8
+ - tsc
9
+ - find . -not -path "./node_modules/*" -type f -iname \*.js -delete
10
+ - parcel build --target node development/index.ts
11
+ - cp -r dist/index.js index.js
12
+ - gapi build clean
13
+ clean:
14
+ - rm -rf dist
15
+ - rm -rf .cache
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@rxdi/hapi",
3
+ "version": "0.7.118",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/rxdi/hapi"
7
+ },
8
+ "scripts": {
9
+ "build": "tsc || true"
10
+ },
11
+ "author": {
12
+ "name": "Kristian Tachev(Stradivario)",
13
+ "email": "kristiqn.tachev@gmail.com"
14
+ },
15
+ "keywords": [
16
+ "graphql",
17
+ "gapi",
18
+ "node",
19
+ "hapi"
20
+ ],
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/rxdi/hapi/issues"
24
+ },
25
+ "homepage": "https://github.com/rxdi/hapi#readme",
26
+ "main": "./dist/main.js",
27
+ "types": "./dist/main.d.ts",
28
+ "module": "./dist/main.js",
29
+ "typings": "./dist/main.d.ts",
30
+ "dependencies": {
31
+ "hapi": "^18.1.0",
32
+ "inert": "^5.1.3",
33
+ "opn": "^6.0.0"
34
+ },
35
+ "devDependencies": {
36
+ "@rxdi/core": "^0.7.117",
37
+ "@types/hapi": "^18.0.4",
38
+ "@types/node": "^12.0.10",
39
+ "typescript": "^3.9.3"
40
+ }
41
+ }