This repository has been archived by the owner on Dec 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
62 lines (47 loc) · 1.48 KB
/
app.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
// Load the dotfiles.
require("dotenv").load({ silent: true });
var express = require("express");
// var cors = require("cors");
// Middleware!
var bodyParser = require("body-parser");
var methodOverride = require("method-override");
var morgan = require("morgan");
var mongoose = require("mongoose");
var port = process.env.PORT || 3000;
var database =
process.env.DATABASE ||
process.env.MONGODB_URI ||
"mongodb://localhost:27017";
var settingsConfig = require("./config/settings");
var adminConfig = require("./config/admin");
var app = express();
// Connect to mongodb
mongoose
.connect(database, {
useCreateIndex: true,
useNewUrlParser: true,
useUnifiedTopology: true
})
.catch(error => console.error(error));
app.use(morgan("dev"));
// app.use(cors());
app.use(
bodyParser.urlencoded({
extended: true
})
);
app.use(bodyParser.json());
app.use(methodOverride());
app.use(express.static(__dirname + "/app/client/build"));
app.use(express.static(__dirname + "/app/legacy"));
// Routers =====================================================================
var apiRouter = express.Router();
require("./app/server/routes/api")(apiRouter);
app.use("/api", apiRouter);
var authRouter = express.Router();
require("./app/server/routes/auth")(authRouter);
app.use("/auth", authRouter);
require("./app/server/routes")(app);
// listen (start app with node server.js) ======================================
app.listen(port);
console.log("App listening on port " + port);