-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
30 lines (29 loc) · 829 Bytes
/
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
const { graphqlHTTP } = require("express-graphql");
const mongoose = require("mongoose");
const gqlschema = require("./backend/GQLSchema.js");
const express = require("express");
const cors = require("cors");
const app = express();
const port = 4000;
//Connecting to the database
mongoose.connect(
gqlClusterDBURL, { useNewUrlParser: true, useUnifiedTopology: true },
() => {
console.log("Connected to mongoDB");
}
);
//Access to data somewhere other than the origin (access from other server)
app.use(cors());
//GraphQL middleware to deal with hassle of REST apis
//set graphiql to true to access GUI
app.use(
"/graphql",
graphqlHTTP({
schema: gqlschema,
graphiql: true,
})
);
//port and listener service
app.listen(port, () => {
console.log(`listening to port ${port}`);
});