-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
31 lines (27 loc) · 863 Bytes
/
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
import express from "express";
import mongoose from "mongoose";
import blogRouter from "./routes/blog-routes.js";
import router from "./routes/user-routes.js";
import cors from "cors";
import { config } from "dotenv";
import path from "path";
//import { request } from "http";
const __dirname = path.resolve();
const app = express();
config();
app.use(express.static("public"));
app.use(cors());
app.use(express.json());
app.use("/api/user", router);
app.use("/api/blog", blogRouter);
app.use(express.static(path.join(__dirname, "build")));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "build", "index.html"));
});
mongoose
.connect(process.env.MONGO_URL)
.then(() => app.listen(process.env.PORT))
.then(() =>
console.log("Working and listening to localhost 3000 and Mongo Connected")
)
.catch((err) => console.log(err));