Skip to content

Commit

Permalink
fix: Update http function signature (#222)
Browse files Browse the repository at this point in the history
* update signatures for the http function.
* update available server return types.
  • Loading branch information
tjholm committed Feb 26, 2024
1 parent 8465ff1 commit ac48c7f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/resources/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ import { SERVICE_BIND } from '../constants';
import * as grpc from '@grpc/grpc-js';
import { ClientMessage, HttpProxyRequest } from '@nitric/proto/http/v1/http_pb';
import { Server } from 'http';
import { Http2SecureServer, Http2Server } from 'http2';

type ServerType = Server | Http2Server | Http2SecureServer;

type ListenerFunction =
| ((port: number, callback?: () => void) => Server)
| ((port: number) => Server);
| ((port: number, callback?: () => void) => ServerType | Promise<ServerType>)
| ((port: number) => ServerType | Promise<ServerType>);

interface NodeApplication {
listen: ListenerFunction;
Expand All @@ -46,7 +49,7 @@ export class HttpWorkerOptions {
}
}

const createWorker = (
const createWorker = async (
app: NodeApplication,
port: number,
callback?: () => void
Expand All @@ -72,7 +75,7 @@ const createWorker = (
httpProxyStream.write(clientMessage);
// Start Node application that HTTP proxy sits on
if (process.env.NITRIC_ENVIRONMENT !== 'build') {
const srv = app.listen(port, callback);
const srv = await app.listen(port, callback);

srv.on('close', () => {
httpProxyStream.cancel();
Expand Down

0 comments on commit ac48c7f

Please sign in to comment.