-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
59 lines (47 loc) · 1.78 KB
/
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
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
const express = require("express");
const mongoose = require("mongoose");
const config = require("config");
const path = require("path");
const db = require("./database");
const User = require("./models/User");
const Payment = require("./models/Payment");
const app = express();
app.use(express.json());
User.hasMany(Payment, { as: "payments", foreignKey: "subid" });
Payment.belongsTo(User, { foreignKey: "subid" });
db.authenticate()
.then(() => {
console.log("Authenticated");
db.sync({ force: false });
//db.close();
})
.catch(err => {
console.log("Unable to connect", err);
});
app.use("/api/users", require("./routes/api/users"));
app.use("/api/auth", require("./routes/api/auth"));
app.use("/api/offers", require("./routes/api/offers"));
app.use("/api/activity", require("./routes/api/activity"));
app.use("/api/notifications", require("./routes/api/notifications"));
app.use("/api/postback", require("./routes/api/postback"));
app.use("/api/email", require("./routes/api/email"));
app.use("/api/stats", require("./routes/api/stats"));
app.use("/api/contact", require("./routes/api/contact"));
// Serve static assets if in production
// app.use(express.static("build"));
// app.get("*", (req, res) => {
// res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
// console.log(path.resolve(__dirname, "client", "build", "index.html"));
// });
app.use(express.static("app"));
// app.get("*", (req, res) => {
// res.sendFile(path.resolve(__dirname, "app", "index.html"));
// console.log(path.resolve(__dirname, "app", "index.html"));
// });
/* GET React App */
app.get(["/app", "/app/*"], function(req, res, next) {
res.sendFile(path.join(__dirname, "app", "index.html"));
//console.log("check");
});
const port = process.env.PORT || 5000;
app.listen(port);