-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
77 lines (64 loc) · 1.95 KB
/
app.js
File metadata and controls
77 lines (64 loc) · 1.95 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
66
67
68
69
70
71
72
73
74
75
76
77
require('express-async-errors');
require("dotenv").config();
const express = require("express");
const morgan = require("morgan");
const cors = require("cors");
const path = require("path")
const authRouter = require("./routes/authRoute");
const depositRouter = require("./routes/depositRoute");
const withdrawalRouter = require("./routes/withdrawalRoute");
const investmentRouter = require("./routes/investmentRoute");
const mainRouter = require("./routes/userRoute");
const adminRouter = require("./routes/adminRoute");
const db = require("./models")
const app = express();
const allowedOrigins = [
"https://meme-orbit-admin.netlify.app",
// https://meme-orbit-admin.netlify.app
"http://localhost:5501"
];
const corsOpt = {
origin: allowedOrigins,
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
credentials: true
}
app.set('trust proxy', 1)
app.use(express.json());
app.use(express.static(path.resolve(__dirname, './public')))
app.use(cors(corsOpt));
app.use(morgan("dev"));
// routes
app.use('/api/v1/auth', authRouter);
app.use('/api/v1/withdrawal', withdrawalRouter);
app.use('/api/v1/deposit', depositRouter);
app.use('/api/v1/investment', investmentRouter);
app.use('/api/v1/user', mainRouter);
app.use("/api/v1/admin", adminRouter);
app.get("/health-check", (req,res) =>{
res.status(200).json({
success:true,
msg: 'Health check successful!!'
})
});
const port = process.env.PORT || 3040;
//for prod
db.sequelize.sync({alter: true}).then(() =>{
console.log("Db synced")
app.listen(port,()=>{
console.log(`Server has started on port ${port}.`)
console.log(`You are live now`)
});
}).catch(err =>{
console.error("sync error occurred:", err)
});
//for local
// async function startServer(){
// try {
// app.listen(port,()=>{
// console.log(`server started on port ${port}`)
// });
// } catch (error) {
// console.log(error);
// }
// }
// startServer();