-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (37 loc) · 1.04 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
const express = require("express");
const path = require("path");
const cors = require("cors");
const morgan = require("morgan");
const colors = require("colors");
const dotenv = require("dotenv");
const connectDB = require("./config/db");
const nodeMailer = require("./nodeMailer");
//env config
dotenv.config();
//router import
const userRoutes = require("./routes/userRoutes");
const blogRoutes = require("./routes/blogRoutes");
//mongodb connection
connectDB();
//rest object
const app = express();
//middlewares
app.use(cors());
app.use(express.json());
app.use(morgan("dev"));
//routes
app.use("/api/v1/user", userRoutes);
app.use("/api/v1/blog", blogRoutes);
//static files
app.use(express.static(path.join(__dirname, "./Client/build")));
app.get("*", function (req, res) {
res.sendFile(path.join(__dirname, "./Client/build/index.html"));
});
// Endpoint to handle email sending
app.use(nodeMailer);
// Port
const PORT = process.env.PORT || 5000;
// Start the server
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});