-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
41 lines (36 loc) · 1.04 KB
/
index.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
const { ApolloServer } = require("apollo-server");
const express = require("express");
const mongoose = require("mongoose");
require("dotenv").config();
const MONGODB = process.env.MONGODB;
const PORT = process.env.PORT || 5000;
const typeDefs = require("./graphql/typeDefs");
const resolvers = require("./graphql/resolvers");
const server = new ApolloServer({
typeDefs,
resolvers,
introspection: true,
context: ({ req }) => ({ req }),
});
// if (process.env.NODE_ENV == "production") {
// app.use(express.static("client/build"));
// const path = require("path");
// app.get("*", (req, res) => {
// res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
// });
// }
mongoose
.connect(MONGODB, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
})
.then(() => {
console.log("Connected to mongodb sucessfully");
return server.listen({ port: PORT }).then((res) => {
console.log(`server running at ${res.url}`);
});
})
.catch((err) => {
console.log(err);
});