-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
36 lines (32 loc) · 1.02 KB
/
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
33
34
35
36
const express = require("express");
const bodyParser = require("body-parser");
const { ApolloServer } = require("apollo-server-express");
const mongoose = require("mongoose");
const typeDefs = require("./graphql/schema");
const resolvers = require("./graphql/resolvers");
const isAuth = require("./middleware/auth");
const User = require("./models/users");
const cors = require("cors");
const app = express();
app.use(cors());
app.use(bodyParser.json());
// // bodyParser is needed just for POST.
const port = process.env.PORT || 4000;
const serverGraphQL = new ApolloServer({
typeDefs,
resolvers,
playground: !!(process.env.NODE_ENV !== "production"),
context: isAuth,
});
//apply server graphql in express
serverGraphQL.applyMiddleware({ app, cors: false });
mongoose
.connect(
`mongodb+srv://${process.env.MONGO_USER}:${process.env.MONGO_PASSWORD}@cluster0-uxdk4.mongodb.net/${process.env.MONGO_DB}?retryWrites=true&w=majority`
)
.then(() => {
app.listen(port);
})
.catch((err) => {
console.log(err);
});