-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
41 lines (34 loc) · 1.02 KB
/
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
35
36
37
38
39
40
41
require("dotenv").config();
const { ApolloServer, PubSub } = require("apollo-server");
const mongoose = require("mongoose");
const typeDefs = require("./graphql/typeDefs");
const resolvers = require("./graphql/resolvers");
const pubsub = new PubSub();
const PORT = process.env.port || 8080;
const server = new ApolloServer({
typeDefs,
resolvers,
context: ({ req }) => ({ req, pubsub }),
engine: {
reportSchema: true,
},
});
mongoose
.connect(
`mongodb+srv://${process.env.MONGO_USER}:${process.env.MONGO_PASSWORD}@buro.0gfrl.mongodb.net/${process.env.MONGO_DATABASE}?retryWrites=true&w=majority`,
{
useUnifiedTopology: true,
useNewUrlParser: true,
}
)
.then(() => {
console.log(`🚀 MongoDB Connected - db: ${process.env.MONGO_DATABASE}`);
return server.listen({ port: PORT });
})
.then((res) => {
console.log(`🚀 Server ready at ${res.url}`);
console.log(`🚀 Subscriptions ready at ${res.subscriptionsUrl}`);
})
.catch((err) => {
console.error(err);
});