-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
51 lines (40 loc) · 1.18 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
const express = require("express");
const morgan = require("morgan");
const cors = require("cors");
const bodyParser = require("body-parser");
const colors = require("colors");
const dotenv = require("dotenv");
const connectDB = require("./config/db");
const errorHandler = require('./middlewares/errorMiddleware');
//for deployment
const path = require("path");
//routes path
const authRoutes = require("./routes/authRoutes");
//dotenv
dotenv.config();
//mongo connection
connectDB();
//rest object
const app = express();
//middlewares
app.use(cors());
app.use(express.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(morgan("dev"));
app.use(errorHandler);
const PORT = process.env.PORT || 8080;
//API routes
app.use("/api/v1/auth", authRoutes);
app.use("/api/v1/openai", require("./routes/openaiRoutes"));
//Static Files
app.use(express.static(path.join(__dirname, "./client/build")));
//To access above
app.get('*', function (req, res) {
res.sendFile(path.join(__dirname, "./client/build/index/index.html"));
});
//listen server
app.listen(PORT, () => {
console.log(
`Server Running in ${process.env.DEV_MODE} mode on port no ${PORT}`.bgCyan.white
);
});