Skip to content

Commit

Permalink
Merge pull request #15 from ty-ras/issue/14-expose-koa-options
Browse files Browse the repository at this point in the history
#14 Exposing Koa options to the users of createSe…
  • Loading branch information
stazz authored Aug 19, 2023
2 parents 8d892ec + c59407d commit bee2fb3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ty-ras/server-koa",
"version": "2.0.0",
"version": "2.1.0",
"author": {
"name": "Stanislav Muhametsin",
"email": "[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion server/src/internal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file This file contains internal code for e.g. implementing Node HTTP server -specific functionality of {@link server.ServerFlowCallbacksWithoutState}.
* @file This file contains internal code for e.g. implementing Koa HTTP server -specific functionality of {@link server.ServerFlowCallbacksWithoutState}.
*/

import type * as server from "@ty-ras/server";
Expand Down
18 changes: 16 additions & 2 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,21 @@ export interface ServerCreationOptions<
* Set this to `true` explicitly if automatic detection of server being secure by {@link createServer} fails.
*/
secure?: TSecure | undefined;

/**
* Optional options to {@link Koa} constructor.
*/
koaOptions?: KoaOptions;
}

/**
* This type contains all the options one can give to Koa server.
*/
export type KoaOptions = Exclude<
ConstructorParameters<typeof Koa>[0],
undefined
>;

const secureHttp1OptionKeys: ReadonlyArray<keyof tls.TlsOptions> = [
"key",
"cert",
Expand Down Expand Up @@ -227,11 +240,12 @@ const createHandleHttpRequest = <
endpoints,
createState,
events,
koaOptions,
}: Pick<
ServerCreationOptions<TStateInfo, TState, never, never>,
"endpoints" | "createState" | "events"
"endpoints" | "createState" | "events" | "koaOptions"
>): HTTP1Or2Handler<TRequest, TResponse> => {
return new Koa()
return new Koa(koaOptions)
.use(middleware.createMiddleware(endpoints, createState, events))
.callback();
};
Expand Down

0 comments on commit bee2fb3

Please sign in to comment.