-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
47 lines (38 loc) · 1.1 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
var express = require("express")
var cors = require("cors")
var bodyParser = require("body-parser")
var app = express()
var path = require("path")
var PORT = process.env.PORT || 3001
var db = require("./models")
// Serve up static assets
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
}
app.use(bodyParser.json())
app.use(cors())
app.use(bodyParser.urlencoded({
extended: false
}))
var Users = require("./routes/Users")
var Currencies = require("./routes/Currencies")
app.use("/users", Users)
app.use("/currencies", Currencies)
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
app.get("/*", function(req, res) {
res.sendFile(path.join(__dirname, "./client/build/index.html"));
});
}
else {
app.use(express.static(path.join(__dirname, '/client/public')));
app.get("/*", function(req, res) {
res.sendFile(path.join(__dirname, "./client/public/index.html"));
});
}
db.sequelize.sync({
force: false }).then(function () {
app.listen(PORT, function () {
console.log("App listening on PORT " + PORT);
});
});