-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.ts
More file actions
29 lines (26 loc) · 837 Bytes
/
mod.ts
File metadata and controls
29 lines (26 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { Server, GraphQLHTTP } from './deps.ts'
import shark from './shark.ts'
export class Shark {
endpoints: string[];
server: Server;
constructor(endpoints: string[]) {
this.endpoints = endpoints;
this.server = new Server();
}
async use(middleware: any) {
await this.server.use(middleware);
}
async listen(port: number = parseInt(Deno.env.get("PORT")) || 8000) {
const { schema, rootValue } = await shark(this.endpoints);
this.server.post(
"/graphql",
async (ctx: any, next: any) => {
const resp = await GraphQLHTTP({ schema, rootValue, context: (request) => ({ request }), graphiql: true })(ctx.req);
ctx.res = resp;
await next();
},
);
console.log(`Shark server listen to http://localhost:${port}`);
await this.server.listen({ port });
}
}