-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (37 loc) · 1.05 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: ".env" });
const { ApolloServer } = require("apollo-server-express");
const mongoose = require("mongoose");
const express = require("express");
const cors = require("cors");
const typeDefs = require("./graphql/typeDefs");
const resolvers = require("./graphql/resolvers/index");
const PORT = process.env.PORT || 5000;
const LOCAL_SERVER = true;
const server = new ApolloServer({
cors: {
origin: "*",
credentials: true,
},
typeDefs,
resolvers,
context: ({ req }) => ({ req }),
});
const app = express();
server.applyMiddleware({ app });
var corsOptions = {
origin: LOCAL_SERVER
? "http://localhost:3000"
: "https://merng-social-orchan.netlify.app/",
credentials: true,
};
app.use(express.static("public"));
app.use(cors(corsOptions));
mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
});
app.listen({ port: PORT }, () => {
console.log("connected to database :)");
// console.log(`server running at http://localhost:${PORT}`);
});