-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathapp.js
57 lines (46 loc) · 1.61 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
const express = require("express");
const fileUpload = require("express-fileupload");
const path = require("path");
const connectDB = require("./config/db");
const dotenv = require("dotenv");
const viewsRouter = require("./routes/viewsRoutes");
const newsRouter = require("./routes/gymkhana/newsRoutes");
const secretaryRouter = require("./routes/gymkhana/secretaryRoutes");
const senateRouter = require("./routes/gymkhana/senateRoutes");
const societiesRouter = require("./routes/gymkhana/societiesRoutes");
const hostelsRouter = require("./routes/gymkhana/hostelsRoutes");
// INITIALIZING EXPRESS APP
const app = express();
app.use(express.urlencoded({extended:false}));
app.use(express.json());
app.use(fileUpload());
// SETTING DEFAULT VIEW ENGINE
app.set("view engine", "ejs");
// SETTING DEFAULT VIEWS FOLDER
app.set("views", path.join(__dirname, "views"));
// SERVING STATIC FILES
app.use(express.static(`${__dirname}/public`));
dotenv.config({ path: "./config/config.env" });
// DATABASE CONNECTION
connectDB();
// ALL ROUTES
app.use("/", viewsRouter);
app.use("/gymkhana/news", newsRouter);
app.use("/gymkhana/hostels", hostelsRouter);
app.use("/gymkhana/secretary", secretaryRouter);
app.use("/gymkhana/societies", societiesRouter);
app.use("/gymkhana/senate", senateRouter);
// IF ROUTE NOT PRESENT THEN THIS WILL RUN
app.all("*", (req, res) => {
return res.status(404).json({
message: "can't find this url",
});
});
// START EXPRESS APP
port = process.env.PORT || 9000;
app.listen(port, (err) => {
if (err) throw err;
console.log(`App listening on port : ${port}
http://localhost:9000
`);
});