-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
34 lines (25 loc) · 990 Bytes
/
server.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
33
34
const { ApolloServer } = require('apollo-server-express');
const path = require('path');
const express = require('express');
const typeDefs = require('./graphql/typeDefs');
const resolvers = require('./graphql/resolvers');
const authService = require('./services/auth');
const { RequireAuthDirective } = require('./graphql/directives');
const PORT = process.env.PORT || 8888;
require('./utils/db');
const app = express();
app.get('/todo', (req, res) => {
res.json({ title: "From Server" });
});
const server = new ApolloServer({
typeDefs,
resolvers,
schemaDirectives: { requireAuth: RequireAuthDirective },
context: ({ req }) => authService.getUserFromAuthHeader(req.headers.authorization)
});
server.applyMiddleware({ app });
app.use(express.static(path.join(__dirname, 'client', 'build')));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'client', 'build', 'index.html'));
});
app.listen(PORT, () => console.log(`listening on ${PORT}`) );