-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
41 lines (35 loc) · 1.11 KB
/
server.js
File metadata and controls
41 lines (35 loc) · 1.11 KB
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
"use strict";
import express from "express";
import { graphqlHTTP } from "express-graphql";
import { schema } from "./src/schema.js";
import { root } from "./src/root.js";
import { ENV, printENV } from "./src/envVars.js";
import VALIDATION_RULES from "./src/validation.js";
// Hardcoded because school project and not production system
const PORT = 8080;
const app = express();
// Logging requests through middleware
app.use((req, _res, next) => {
console.log(`Request: ${req.url}${JSON.stringify(req.params)}`);
next();
});
// Defining the graphql server through middleware
app.use(
"/graphql",
graphqlHTTP({
schema: schema,
rootValue: root,
// Allow or disallow GraphiQL GUI via environment variable ALLOW_GRAPHIQL
graphiql: ENV.ALLOW_GRAPHIQL,
// The validation rules set in src/validation.js
validationRules: VALIDATION_RULES,
})
);
// Start server listenig on the hardcoded port,
// Additionally printing out all selected environment variables
app.listen({ port: PORT }, () => {
console.log(`Listening on port: ${PORT}\n`);
printENV();
//Just to get a line break
console.log();
});