-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.js
76 lines (66 loc) · 2.6 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const express = require("express");
const fileUpload = require("express-fileupload");
const path = require("path");
const connectDB = require("./config/db");
const dotenv = require("dotenv");
const morgan=require("morgan");
const bodyparser=require("body-parser")
const viewsRouter = require("./routes/viewsRoutes");
const blogsRouter = require("./routes/blogsRoutes");
const projectsRouter = require("./routes/projectsRoutes");
const openSource_routes = require("./routes/openSourceRoutes");
const ICPC_routes = require("./routes/ICPCRoutes");
const Hof_routes = require("./routes/HofRoutes");
const interIIT_routes=require("./routes/interIITRoutes");
// 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(morgan(`tiny`));
app.use(bodyparser.urlencoded({extended:true}));
app.use(express.static(`${__dirname}/public`));
app.use("/css",express.static(path.resolve(__dirname,"assets/CSS")))
app.use("/interIIT/css",express.static(path.resolve(__dirname,"assets/CSS")))
app.use("/projects/css",express.static(path.resolve(__dirname,"assets/CSS")))
app.use("/js",express.static(path.resolve(__dirname,"assets/js")))
dotenv.config({ path: "./config/config.env" });
// DATABASE CONNECTION
connectDB();
// ALL ROUTES
app.use("/", viewsRouter);
app.use("/projects", projectsRouter);
app.use("/blogs", blogsRouter);
app.use("/openSource/", openSource_routes);
app.use("/ICPC/", ICPC_routes);
app.use("/Hof/", Hof_routes);
app.use("/interIIT",interIIT_routes);
// 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 || 5000;
app.listen(port, (err) => {
if (err) throw err;
console.log(`App listening on port : ${port}
http://localhost:5000
`);
});