-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (48 loc) · 1.79 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
58
59
const app = require("express")();
const http = require("http");
require("dotenv").config();
// parse the json formats
const bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// show the requests
app.use(require("morgan")("dev"));
// cross request resolver
app.use(require("cors")());
require("mongoose").connect(
`mongodb://localhost/nagarjuna-college-management`,
// `mongodb+srv://sangya2058:Carrier@[email protected]/nagarjuna-college-management?retryWrites=true&w=majority`,
{
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true
},
err => {
if (err) return console.log(err);
else console.log("Database: Connected => nagarjuna-college-management");
}
);
//auth middleware
const {userTokenValidation} = require("./middleware/authentication");
// api paths
// app.use("/api/admin/accounts", require("./routes/accounts"));
app.use("/api/admin/accounts", userTokenValidation, require("./routes/accounts"));
// app.use("/api/admin/semester", require("./routes/semester"));
app.use("/api/admin/semester", userTokenValidation, require("./routes/semester"));
app.use("/api/admin/applications", userTokenValidation, require("./routes/applications"));
app.use("/api/admin/authentication", require("./routes/authentication"));
// const path = require('path');
// app.use(require("express").static(path.join(__dirname, 'client/build')));
// app.get('/*', (req, res) => {
// res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
// });
// unknown request
app.use("/api",(req, res) => {
res.status(404).json({
msg: "404 API not found!"
});
});
const PORT = process.env.PORT || 8080;
http.createServer(app).listen(PORT, () => {
console.log(`Server: Running => ${PORT}`);
});