Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/apps/src/http/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface IHttpServerAdapter {
* Not needed if app.start() is not called
* @param port Port number to listen on
*/
start?(port: number): Promise<void>;
start?(port: number | string): Promise<void>;

/**
* Stop the server from listening and perform any cleanup that needs to be done
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/src/http/express-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class ExpressAdapter implements IHttpServerAdapter {
/**
* Start the server listening on the specified port
*/
async start(port: number): Promise<void> {
async start(port: number | string): Promise<void> {
return new Promise<void>((resolve, reject) => {
// Handle startup errors
this.server.once('error', (err) => {
Expand Down
14 changes: 11 additions & 3 deletions packages/apps/src/http/http-server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MockAdapter implements IHttpServerAdapter {
this.routes.push({ method, path, handler });
}

async start(_port: number): Promise<void> {
async start(_port: number | string): Promise<void> {
this.started = true;
}

Expand Down Expand Up @@ -151,12 +151,20 @@ describe('HttpServer', () => {
expect(adapter.started).toBe(true);
});

it('should parse string port to number', async () => {
it('should pass string port through to adapter', async () => {
const startSpy = jest.spyOn(adapter, 'start');

await server.start('4000');

expect(startSpy).toHaveBeenCalledWith(4000);
expect(startSpy).toHaveBeenCalledWith('4000');
});

it('should pass named pipe path through to adapter', async () => {
const startSpy = jest.spyOn(adapter, 'start');

await server.start('\\\\.\\pipe\\507cb72a-6765-4f1e-a9f0-1234abcd5678');

expect(startSpy).toHaveBeenCalledWith('\\\\.\\pipe\\507cb72a-6765-4f1e-a9f0-1234abcd5678');
});

it('should throw when adapter does not implement start', async () => {
Expand Down
3 changes: 1 addition & 2 deletions packages/apps/src/http/http-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,13 @@ export class HttpServer implements IHttpServer {
* Called by App.start()
*/
async start(port: number | string) {
const portNumber = typeof port === 'string' ? parseInt(port, 10) : port;
if (!this._adapter.start) {
throw new Error(
'Adapter does not implement start(). ' +
'Either implement start() in your adapter, or manage server lifecycle manually.'
);
}
await this._adapter.start(portNumber);
await this._adapter.start(port);
}

/**
Expand Down
Loading