-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from ty-ras/issue/33-add-specific-listen-funct…
…ionality #33 Adjusting to newer version of generic server …
- Loading branch information
Showing
6 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* @file This file contains unit tests for functionality in file `../listen.ts`. | ||
*/ | ||
|
||
import test from "ava"; | ||
|
||
import getPort from "@ava/get-port"; | ||
import * as spec from "../listen"; | ||
import * as server from "../server"; | ||
|
||
test("Validate that listening to server does not crash", async (c) => { | ||
// Not much else we can do since CORS callbacks are just call-thru to @ty-ras/server functionality | ||
c.plan(1); | ||
await c.notThrowsAsync(async () => { | ||
await spec.listenAsync( | ||
server.createServer({ endpoints: [] }), | ||
"localhost", | ||
await getPort(), | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
export type * from "./context.types"; | ||
export * from "./server"; | ||
export * from "./cors"; | ||
export * from "./listen"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* @file This file contains function that can be used to expose uniform way to listen to TyRAS servers. | ||
*/ | ||
|
||
import * as net from "node:net"; | ||
import type * as server from "./server"; | ||
import * as serverGeneric from "@ty-ras/server"; | ||
|
||
/** | ||
* The helper function to listen to given {@link server.HttpServer} asynchronously. | ||
* @param server The {@link server.HttpServer} to listen to. | ||
* @param host The hostname as string. | ||
* @param port The port as number. | ||
* @param backlog The backlog parameter, if any. | ||
* @returns Asynchronously nothing. | ||
*/ | ||
export function listenAsync( | ||
server: server.HttpServer, | ||
host: string, | ||
port: number, | ||
backlog?: number, | ||
): Promise<void>; | ||
|
||
/** | ||
*The helper function to listen to given {@link server.HttpServer} asynchronously. | ||
* @param server The {@link server.HttpServer} to listen to. | ||
* @param options The options for listening. | ||
* @returns Asynchronously nothing. | ||
*/ | ||
export function listenAsync( | ||
server: server.HttpServer, | ||
options: net.ListenOptions, | ||
): Promise<void>; | ||
|
||
/** | ||
* The helper function to listen to given {@link server.HttpServer} asynchronously. | ||
* @param server The {@link server.HttpServer} to listen to. | ||
* @param hostOrOptions The {@link net.ListenOptions}. | ||
* @param port The port to listen to. | ||
* @param backlog The backlog parameter, if any. | ||
* @returns Asynchronously nothing. | ||
*/ | ||
export function listenAsync( | ||
server: server.HttpServer, | ||
hostOrOptions: string | net.ListenOptions, | ||
port?: number, | ||
backlog?: number, | ||
) { | ||
return serverGeneric.listenAsyncGeneric(server, hostOrOptions, port, backlog); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters