-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (36 loc) · 1.21 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
const express = require('express');
const authRoute = require('./routes/auth');
const userRoute = require('./routes/user');
const notesRoute = require('./routes/note');
const dotenv = require('dotenv');
const mongoose = require('mongoose');
const path = require("path");
const app = express();
dotenv.config();
mongoose.connect(
process.env.MONGO_CONNECT_STR
)
.then(() => console.log("db connected.."))
.catch((error) => {
console.log(error)
console.log("failed db connection..")
})
/* enable CORS */
// app.use((req, res, next) => {
// res.header("Access-Control-Allow-Origin","*");
// res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, authorization, User-Agent");
//res.header("Access-Control-Allow-Methods: GET, POST");
// next();
// });
app.use(express.json());
app.use("/api/auth", authRoute);
app.use("/api/users", userRoute);
app.use("/api/notes", notesRoute);
// child folder static
app.use(express.static(path.join(__dirname, "/todosite_client/build")));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '/todosite_client/build', 'index.html'));
});
app.listen( process.env.PORT || 5000, () => {
console.log("server is running!!");
});