-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
49 lines (41 loc) · 1.3 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
const db = require("./db");
const { APP_PORT } = require("./configvar");
const {
corsOptions,
crossOriginResourceSharing,
handleNotFound,
} = require("./helpers/essentialfunc");
const express = require("express");
const morgan = require("morgan");
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const cors = require("cors");
const port = APP_PORT || 9000;
//bringing router
const userRoutes = require("./routes/User");
const tradeRoutes = require("./routes/Trades");
const accountRoutes = require("./routes/Account");
const reportRoutes = require("./routes/Reports");
const tradingsystemRoutes = require("./routes/Tradingsystem");
const app = express();
app.use("/uploads", express.static("uploads"));
//middlewares
app.use(morgan("dev")); // logs routes in console
app.use(bodyParser.json());
app.use(cookieParser());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(crossOriginResourceSharing);
app.use(cors(corsOptions));
//route here
app.use("/api", userRoutes);
app.use("/api", tradeRoutes);
app.use("/api", accountRoutes);
app.use("/api", reportRoutes);
app.use("/api", tradingsystemRoutes);
// this handles 404 error it must be here
app.use(handleNotFound);
//port
app.listen(port, () => {
console.log(`Server started at ${port}`);
});