-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
65 lines (49 loc) · 1.75 KB
/
index.js
File metadata and controls
65 lines (49 loc) · 1.75 KB
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
57
58
59
60
61
62
63
64
65
const express = require('express');
const app = express();
app.use(express.json());
const mongoose = require('mongoose');
var cors = require('cors');
app.use(cors());
// const helmet=require('helmet');
// app.use(helmet({
// contentSecurityPolicy:false,
// }))
const dotenv = require("dotenv");
dotenv.config({ path: "./config.env" });
const { JWT_SECRET, MONGODB_URI } = require("./config/keys");
const port = 5000;
// const MONGODB_URI =
// "mongodb://avnesh:Ak2566@ac-hpvuaqp-shard-00-00.y5vq4ih.mongodb.net:27017,ac-hpvuaqp-shard-00-01.y5vq4ih.mongodb.net:27017,ac-hpvuaqp-shard-00-02.y5vq4ih.mongodb.net:27017/?ssl=true&replicaSet=atlas-oiw14b-shard-0&authSource=admin&retryWrites=true&w=majority";
const connectparams = {
useNewUrlParser: true,
useUnifiedTopology: true,
};
mongoose.set('strictQuery', 'true');
const connectTomongo = () => {
mongoose.connect(MONGODB_URI, connectparams).then(() => {
console.log("connected to mongo Succesfully");
}).catch((error) => {
console.log(error);
})
}
connectTomongo();
// app.get('/', (req, res) => {
// res.send("Hello world");
// });
// app.use((req,res,next)=>{
// res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
// res.setHeader("Cross-Origin-Opener-Policy", "same-origin-allow-popups");
// next();
// });
app.use('/api/auth', require('./routes/auth'));
app.use('/api/invest', require('./routes/invest'));
if (process.env.NODE_ENV == "production") {
const path = require("path");
app.get("/", (req, res) => {
app.use(express.static(path.resolve(__dirname, "client", "build")));
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
}
app.listen(port, () => {
console.log(`App listening on port https://localhost:${port}`);
})