-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
56 lines (49 loc) · 1.26 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
const express = require("express");
const bodyParser = require("body-parser");
const path = require("path");
const compression = require("compression");
const cors = require("cors");
const morgan = require("morgan");
const { notFound, sendErrors } = require("./config/errorHandler");
const app = express();
require("dotenv").config();
require("./config/dbconnection");
app.use(cors({ exposedHeaders: "x-auth-token" }));
app.use(express.static(path.join(__dirname, "public")));
app.use("/uploads", express.static(path.join(__dirname, "uploads")));
app.use(
bodyParser.urlencoded({
limit: "50mb",
extended: true,
parameterLimit: 1000000
})
);
app.use(
bodyParser.json({
limit: "50mb",
extended: true,
parameterLimit: 1000000
})
);
app.use(morgan("dev"));
//load Schemas
const User = require("./models/User");
//Routes
app.use("/api/v1/", require("./routes/api/v1/index"));
app.use("*", notFound);
//Error Handlers
app.use(sendErrors);
const { ENV, PORT } = require("./config/index");
//Setting up server
(startServer = async () => {
try {
await app.listen(PORT);
console.log(
`ENV: ${
ENV == "dev" ? "Development" : "Production"
}\nServer is up and running on Port ${PORT}`
);
} catch (err) {
console.error("Error in running server.", err);
}
})();