-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
62 lines (54 loc) · 1.56 KB
/
index.ts
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env node
/* eslint-disable no-console */
import chalk from "chalk";
import { createServer } from "http";
import { getShutdownActions, makeApp } from "./app";
// @ts-ignore
const packageJson = require("../../../package.json");
async function main() {
// Create our HTTP server
const httpServer = createServer();
// Make our application (loading all the middleware, etc)
const app = await makeApp({ httpServer });
// Add our application to our HTTP server
httpServer.addListener("request", app);
// And finally, we open the listen port
const PORT = parseInt(process.env.PORT || "", 10) || 3000;
httpServer.listen(PORT, () => {
const address = httpServer.address();
const actualPort: string =
typeof address === "string"
? address
: address && address.port
? String(address.port)
: String(PORT);
console.log();
console.log(
chalk.green(
`${chalk.bold(packageJson.name)} listening on port ${chalk.bold(
actualPort
)}`
)
);
console.log();
console.log(
` Site: ${chalk.bold.underline(`http://localhost:${actualPort}`)}`
);
console.log(
` GraphiQL: ${chalk.bold.underline(
`http://localhost:${actualPort}/graphiql`
)}`
);
console.log();
});
// Nodemon SIGUSR2 handling
const shutdownActions = getShutdownActions(app);
shutdownActions.push(() => {
httpServer.close();
});
}
main().catch((e) => {
console.error("Fatal error occurred starting server!");
console.error(e);
process.exit(101);
});