forked from benjie/ouch-my-finger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server-express.mjs
27 lines (22 loc) · 882 Bytes
/
server-express.mjs
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
// @ts-check
import express from "express";
import { grafserv } from "grafserv/express/v4";
import { postgraphile } from "postgraphile";
import preset from "./graphile.config.mjs";
// Create an express app
const app = express();
// Create a PostGraphile instance
const pgl = postgraphile(preset);
// And extract the resolved preset
const resolvedPreset = pgl.getResolvedPreset();
// Create a Grafserv instance using the grafserv/express/v4 adaptor
const serv = pgl.createServ(grafserv);
// Start the Express server
const port = resolvedPreset.grafserv?.port ?? 5678;
const host = resolvedPreset.grafserv?.host ?? "127.0.0.1";
const server = app.listen(port, host, () => {
console.log(`Server running on http://${host}:${port}/`);
});
// Mount our Grafserv instance into our Express app, passing the HTTP server so
// we can attach websocket support.
serv.addTo(app, server);