server.js
1.36 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import dotenv from "dotenv";
dotenv.config();
import express from "express";
import bodyParser from "body-parser";
import cors from "cors";
import helmet from "helmet";
import csp from "helmet-csp";
import expressPlayground from "graphql-playground-middleware-express";
import { ApolloServer } from "apollo-server-express";
import morgan from "morgan";
import "./passport";
import { authenticateJWT } from "./passport";
import schema from "./schema";
const PORT = process.env.PORT;
const server = new ApolloServer({
schema,
});
const app = express();
app.use(helmet());
app.use(
csp({
directives: {
defaultSrc: ["'self'"],
styleSrc: ["'self'", "'unsafe-inline'"],
styleSrcElem: [
"'self'",
"fonts.googleapis.com",
"cdn.jsdelivr.net",
"'unsafe-inline'",
],
imgSrc: ["'self'", "cdn.jsdelivr.net"],
scriptSrcElem: ["'self'", "cdn.jsdelivr.net", "'unsafe-inline'"],
fontSrc: ["'self'", "'unsafe-inline'", "fonts.gstatic.com"],
},
})
);
app.use(bodyParser.json(), cors());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(morgan("dev"));
app.use(authenticateJWT);
app.get("/", expressPlayground({ endpoint: "/graphql" }));
server.applyMiddleware({ app });
const handleListening = () => {
console.log(`Server ready at http://localhost:${PORT}`);
};
app.listen(PORT, handleListening);