-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
87 lines (76 loc) · 2.42 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const express = require("express");
const path = require("path");
const app = express();
const bodyParser = require("body-parser");
const cookieSession = require("cookie-session");
const mongoose = require("mongoose");
const passport = require("passport");
const MongoClient = require("mongodb").MongoClient;
// GrpahQL related dependencies
const graphQLSchema = require("./graphql/schema/index");
const rootResolver = require("./graphql/resolver/index");
const graphQLHttp = require("express-graphql");
//-----------------------------
const user = require("./routes/user.route");
const github = require("./routes/github.route");
const auth = require("./routes/auth.route");
const task = require("./routes/task.route");
let dev_db_url =
process.env.MONGODB_URI || "mongodb://127.0.0.1:27017/JiraBackEnd";
// Serve static files from the React app
app.use(express.static(path.join(__dirname, "client/build")));
mongoose.connect(
dev_db_url,
{ useNewUrlParser: true, useFindAndModify: false },
function(err, db) {
if (err) {
throw err;
}
console.log("Mongoose successfully connected to database");
}
);
mongoose.Promise = global.Promise;
MongoClient.connect(dev_db_url, { useNewUrlParser: true }, function(err, db) {
if (err) {
throw err;
}
console.log("Mongodb is running on port", db.topology.s.port);
});
console.log("Running passport related functions");
require("./services/gitpass")(passport);
app.use(
cookieSession({
maxAge: 30 * 24 * 60 * 60 * 1000,
keys: ["indasjdNSd421$SDssssma$s"]
})
);
app.use(passport.initialize());
app.use(passport.session());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// Put all API endpoints under '/api'
app.use("/user", user);
//app.use('/card',card);
app.use("/", github);
app.use("/", auth);
app.use("/api", task);
app.use(
"/graphql",
graphQLHttp(req => ({
schema: graphQLSchema,
rootValue: rootResolver,
context: { requestBody: req, user: req.user },
graphiql: process.env.NODE_ENV !== "production"
}))
);
// The "catchall" handler: for any request that doesn't
// match one above, send back React's index.html file.
if (process.env.NODE_ENV == "production") {
app.get("*", (req, res) => {
console.log("CAN YOU HEAR ME");
res.sendFile(path.join(__dirname + "/client/build/index.html"));
});
}
const port = process.env.PORT || 8080;
app.listen(port);
console.log(`Password generator listening on ${port}`);