-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
46 lines (37 loc) · 1.05 KB
/
app.js
File metadata and controls
46 lines (37 loc) · 1.05 KB
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
46
const express = require("express");
const bodyParser = require("body-parser");
const { graphqlHTTP } = require("express-graphql");
const mongoose = require("mongoose");
const cors = require("cors");
require('dotenv').config()
//graphQL
const gqlResolver = require("./graphql/resolvers");
const isAuth = require("./middleware/isAuth");
// since this is no longer used the line below can be deleted
const gqlSchema = require("./graphql/schema");
const { schemaWithPermissions } = require("./middleware/permissions");
const app = express();
app.use(cors());
app.use(bodyParser.json());
app.use(isAuth);
app.get("/", function (req, res, next) {
res.send("Up!");
});
app.use(
"/graphql",
graphqlHTTP({
schema: schemaWithPermissions,
rootValue: gqlResolver,
graphiql: true,
})
);
mongoose
.connect(
`mongodb+srv://${process.env.MONGO_USER}:${process.env.MONGO_PASSWORD}@cluster0.z2shlde.mongodb.net/${process.env.MONGO_DB}?retryWrites=true&w=majority`
)
.then(() => {
app.listen(3000);
})
.catch((err) => {
console.log(err);
});