Skip to content

Commit

Permalink
feat: [ApiServer] add enabled flag (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
wirwolf authored May 12, 2020
1 parent d0bc356 commit 3e28e8e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/src/Config/app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export class ConfigFactory {
blockNotify: envBoolean('APP_BLOCKCHAIN_NOTIFY_NEW_BLOCK', true),
},
apiServer: {
enabled: envBoolean('APP_API_SERVER_ENABLED', false),
host: env('APP_API_SERVER_HOST', '*'),
port: parseInt(env('APP_API_SERVER_PORT', 3000), 10),
timeout: parseInt(env('APP_API_SERVER_REQUEST_TIMEOUT'), 10)
Expand Down
7 changes: 7 additions & 0 deletions app/src/Modules/Api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class ApiServer {
}

public init(daemon: Daemon): ApiServer {

this.daemon = daemon;

this.koa = new Koa();
Expand Down Expand Up @@ -51,7 +52,12 @@ export class ApiServer {
}

public listen(): Promise<ApiServer> {

return new Promise<ApiServer | any>((resolve, reject) => {
if (!this.config.enabled) {
Core.info('Module ApiServer is not enabled');
resolve(this);
}
this.koa.use(async (ctx, next) => {
try {
await next();
Expand Down Expand Up @@ -89,6 +95,7 @@ export class ApiServer {


export interface ApiServerConfigInterface {
enabled: boolean;
host: string;
port: number;
timeout: number;
Expand Down
3 changes: 2 additions & 1 deletion app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ Core.info('Init services');
nodeApi.init();
monitoring.init(nodeApi);
notify.init();
apiServer.init(daemon);

Promise.all([
apiServer.init(daemon).listen(),
apiServer.listen(),
daemon.start(),
pmx.register(),
notify.run()
Expand Down
1 change: 1 addition & 0 deletions docs/guide-ru/env-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
| Название переменной | Тип | Значение по умолчанию | Описание |
|:-------------------------------|:-------|:----------------------|:------------------------------------------|
| APP_API_SERVER_ENABLED | bool | false | Влкючение модуля прослойки api |
| APP_API_SERVER_HOST | string | * | С каких интерфейсов принимать запросы |
| APP_API_SERVER_PORT | number | 3000 | Порт, на котором будет висеть http сервер |
| APP_API_SERVER_REQUEST_TIMEOUT | number | default | Временной лимит на запрос |
Expand Down

0 comments on commit 3e28e8e

Please sign in to comment.