Skip to content

Commit d27a2da

Browse files
committed
Export Context type
1 parent 68f0052 commit d27a2da

File tree

5 files changed

+10
-14
lines changed

5 files changed

+10
-14
lines changed

README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,14 @@ server({
1616
},
1717
})
1818
.then(() => {
19-
// eslint-disable-next-line no-console
20-
console.log(`Server started on port ${config?.server?.port}`);
19+
console.log(`Server started on port 3001`);
2120
})
2221
.catch((error: Error) => {
23-
// eslint-disable-next-line no-console
2422
console.error("The server couldn't start up...");
25-
// eslint-disable-next-line no-console
2623
console.error(error.message);
27-
db.disconnect();
2824
});
2925

3026
process.once("SIGUSR2", async function () {
31-
await db.disconnect();
3227
process.kill(process.pid, "SIGUSR2");
3328
});
3429
```

src/bootstrap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import { configBuilder } from "./configBuilder";
1010
import {
1111
Bootstrap_T,
1212
Config_T,
13-
Context_T,
13+
Context,
1414
JSONObject_T,
1515
Method_T,
1616
RouteMetadata_T,
1717
StringValueObject_T,
1818
} from "./types";
1919

20-
export const bootstrap = async <T extends Context_T>(
20+
export const bootstrap = async <T extends Context>(
2121
config: Config_T
2222
): Promise<Bootstrap_T> => {
2323
// Validate config and fix paths

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export { HTTPRedirect } from "./HTTPRedirect";
33
export { server } from "./server";
44
export { configBuilder } from "./configBuilder";
55
export { bootstrap } from "./bootstrap";
6+
export { Context } from "./types";
67
export * as helpers from "./helpers";

src/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import Koa from "koa";
66
import mime from "mime-types";
77

88
import { HTTPRedirect } from "./HTTPRedirect";
9-
import { Config_T, Context_T, JSONValue_T, Method_T, Server_T } from "./types";
9+
import { Config_T, Context, JSONValue_T, Method_T, Server_T } from "./types";
1010
import { bootstrap } from "./bootstrap";
1111

12-
export const server = async <T extends Context_T>(
12+
export const server = async <T extends Context>(
1313
config: Config_T
1414
): Promise<Server_T> => {
1515
const { handleRequest } = await bootstrap<T>(config);

src/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export interface Config_T {
5454

5555
export type Method_T = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
5656

57-
export interface RouteMetadata_T<T extends Context_T> {
57+
export interface RouteMetadata_T<T extends Context> {
5858
method: Method_T;
5959
pattern: string;
6060
keys: Key[];
@@ -65,14 +65,14 @@ export interface RouteMetadata_T<T extends Context_T> {
6565

6666
export type ParsedUrlQuery_T = querystring.ParsedUrlQuery;
6767

68-
export interface Context_T {
68+
export interface Context<B = JSONObject_T> {
6969
query: ParsedUrlQuery_T;
7070
params: StringValueObject_T;
71-
body: JSONObject_T;
71+
body: B;
7272
headers: StringValueObject_T;
7373
}
7474

75-
export type RouteHandler_T<T extends Context_T> = (
75+
export type RouteHandler_T<T extends Context> = (
7676
context: T
7777
) => Promise<JSONValue_T>;
7878

0 commit comments

Comments
 (0)