generated from goelaakash79/nodejs-starter-code
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
57 lines (50 loc) · 1.4 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
57
const express = require("express");
const path = require("path");
const bodyParser = require("body-parser");
const morgan = require("morgan");
const cors = require("cors");
const compression = require("compression");
const { notFound, sendErrors } = require("./config/errorHandler");
const app = express();
require("dotenv").config();
require("./config/dbconnection");
app.use(cors({ exposedHeaders: "x-auth-token" }));
app.use(compression());
app.use(express.static(path.join(__dirname, "public")));
app.use(morgan("dev"));
app.use(express.urlencoded({ extended: true }));
app.use(
bodyParser.urlencoded({
limit: "50mb",
extended: true,
parameterLimit: 1000000
})
);
app.use(
bodyParser.json({
limit: "50mb",
extended: true,
parameterLimit: 1000000
})
);
// load schemas
const User = require("./models/User");
const Problem = require("./models/Problem");
const Statistics = require("./models/Statistics");
const Submissions = require("./models/Submissions");
// Routes
app.use("/api/v1/auth", require("./routes/api/v1/auth"));
app.use("/api/v1/users", require("./routes/api/v1/users"));
app.use("/api/v1/code", require("./routes/api/v1/indexRouter"));
app.use("*", notFound);
//Error Handlers
app.use(sendErrors);
app.listen(process.env.PORT, err => {
if (err) {
console.log("Error in running server");
return;
}
console.log(
`Server is up and running on http://localhost:${process.env.PORT}`
);
});