-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
56 lines (46 loc) · 1.2 KB
/
server.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 dotenv = require("dotenv");
dotenv.config();
const express = require("express");
const app = express();
const morgan = require("morgan");
const cors = require("cors");
const port = process.env.PORT || 3000;
const host = "localhost";
// middlewares
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(morgan("dev"));
app.use(cors());
// Calling database and authenticate
const db = require("./database/db");
db.connect((err) => {
if (err) {
throw err;
}
console.log("MYSQL database connected");
});
const tokenMiddleware = require("./middleware/token");
// api route
const apiRouter = require("./routes/api");
app.use("/apis", apiRouter);
// blogs route
const blogRouter = require("./routes/blog");
app.use("/blogs", blogRouter);
// users route
const userRouter = require("./routes/user");
app.use("/users", userRouter);
// verify;
app.get("/test", tokenMiddleware.jwtVerification, (req, res) => {
console.log("User Testing");
res.send("Success");
});
// root route
app.use("*", (req, res) => {
res.status(200);
res.send({
message: "this is the root route",
});
});
app.listen(port, host, () => {
console.log(`Server is running at http://${host}:${port}`);
});