-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (40 loc) · 1.07 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
42
43
44
45
require("dotenv").config({ path: __dirname + "/.env" });
const express = require("express");
const bodyParser = require("body-parser");
const graphqlHttp = require("express-graphql");
const mongoose = require("mongoose");
const cors = require("cors");
const graphQlSchema = require("./schema/index");
const graphQlResolver = require("./resolvers/index");
const app = express();
app.use(bodyParser.json());
app.use(cors());
app.use(
"/graphql",
graphqlHttp({
schema: graphQlSchema,
rootValue: graphQlResolver,
graphiql: true,
introspection: true
})
);
app.get("/", function(req, res) {
res.redirect("/graphql");
});
mongoose
.connect(
`mongodb+srv://${process.env.MONGO_USER}:${
process.env.MONGO_PASSWORD
}@bobbyleeingallsportfolio-lewo7.azure.mongodb.net/${
process.env.MONGO_DB
}?retryWrites=true&w=majority`,
{ useNewUrlParser: true }
)
.then(() => {
app.listen(process.env.PORT || 3000, () => {
console.log(`Server started on port: ${process.env.PORT || 3000}`);
});
})
.catch(err => {
console.log(err);
});