-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
32 lines (29 loc) · 975 Bytes
/
app.js
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
const path = require("path");
const express = require("express");
const morgan = require("morgan");
const helmet = require("helmet");
const cookieParser = require("cookie-parser");
const graphqlHTTP = require("express-graphql");
const schema = require("api/graphql");
const logger = require("utils/logger.js");
const sitePage =
express()
.use(express.static(path.resolve(__dirname, "./public/spa")))
.get("/", (req, res) => {
res.sendFile(path.resolve(__dirname, "./public/spa/index.html"));
});
const graphqlAPI =
express()
.use("/graphql", graphqlHTTP((req, res) => ({
schema,
graphiql: process.env.NODE_ENV !== "production",
context: { req, res }
})));
module.exports =
express()
.use(helmet())
.use(morgan("dev", { stream: logger.consoleStream }))
.use(morgan("common", { stream: logger.fileStream }))
.use(cookieParser())
.use(graphqlAPI)
.use(sitePage);