From b813916c192595dc29a175770c98b51ffb4a8cb8 Mon Sep 17 00:00:00 2001 From: Jerko Steiner Date: Sat, 7 Sep 2019 19:27:21 +0700 Subject: [PATCH] Use simpler interface for Bootstrap app server --- packages/server/src/application/Bootstrap.ts | 7 ++++--- packages/server/src/application/IAppServer.ts | 8 ++++++++ packages/server/src/application/IApplication.ts | 8 +++----- packages/server/src/test-utils/TestUtils.ts | 7 ++++--- 4 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 packages/server/src/application/IAppServer.ts diff --git a/packages/server/src/application/Bootstrap.ts b/packages/server/src/application/Bootstrap.ts index 189a246..38efd9b 100644 --- a/packages/server/src/application/Bootstrap.ts +++ b/packages/server/src/application/Bootstrap.ts @@ -130,13 +130,14 @@ export class Bootstrap implements IBootstrap { await this.database.connect() await new Promise((resolve, reject) => { + const _resolve = () => resolve() if (!port) { - this.server = this.application.server.listen(resolve) + this.server = this.application.server.listen(_resolve) return } else if (typeof port === 'number' && hostname) { - this.server = this.application.server.listen(port, hostname, resolve) + this.server = this.application.server.listen(port, hostname, _resolve) } else { - this.server = this.application.server.listen(port, resolve) + this.server = this.application.server.listen(port, _resolve) } }) diff --git a/packages/server/src/application/IAppServer.ts b/packages/server/src/application/IAppServer.ts new file mode 100644 index 0000000..a53d34c --- /dev/null +++ b/packages/server/src/application/IAppServer.ts @@ -0,0 +1,8 @@ +import { Server } from 'http'; + +export interface IAppServer { + listen(callback?: () => void): Server + listen(callback?: () => void): Server + listen(portOrPath: number | string, callback?: () => void): Server + listen(port: number, hostname: string, callback?: () => void): Server +} diff --git a/packages/server/src/application/IApplication.ts b/packages/server/src/application/IApplication.ts index 9a6d6bb..44050ce 100644 --- a/packages/server/src/application/IApplication.ts +++ b/packages/server/src/application/IApplication.ts @@ -1,9 +1,7 @@ -import express from 'express' -import {AsyncRouter} from '../router' -import {IRoutes} from '@rondo.dev/common' -import {IDatabase} from '../database/IDatabase' +import { IDatabase } from '../database/IDatabase'; +import { IAppServer } from './IAppServer'; export interface IApplication { - readonly server: express.Application + readonly server: IAppServer readonly database: IDatabase } diff --git a/packages/server/src/test-utils/TestUtils.ts b/packages/server/src/test-utils/TestUtils.ts index 82b88c4..c33a640 100644 --- a/packages/server/src/test-utils/TestUtils.ts +++ b/packages/server/src/test-utils/TestUtils.ts @@ -13,12 +13,13 @@ import shortid from 'shortid' import { AddressInfo } from 'net' import { createRemoteClient, FunctionPropertyNames, TAsyncified } from '@rondo.dev/jsonrpc' import {Server} from 'http' +import { IAppServer } from '../application/IAppServer' export class TestUtils { readonly username = `test${process.env.JEST_WORKER_ID}@user.com` readonly password = 'Password10' - readonly app: express.Application + readonly app: IAppServer readonly context: string readonly transactionManager: ITransactionManager @@ -134,7 +135,7 @@ export class TestUtils { return { headers: { - "cookie": [cookies, cookie].join('; '), + 'cookie': [cookies, cookie].join('; '), 'x-csrf-token': token, }, userId: response.body.id, @@ -155,7 +156,7 @@ export class TestUtils { return { headers: { - "cookie": [cookies, cookie].join('; '), + 'cookie': [cookies, cookie].join('; '), 'x-csrf-token': token, }, }