-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
70 lines (61 loc) · 1.78 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import express from "express";
import cookieParser from "cookie-parser";
import mongoose from "mongoose";
import cors from "cors";
import dotenv from "dotenv";
import helmet from "helmet";
import morgan from "morgan";
import payment from './routes/payment.js'
import jwt from "jsonwebtoken"
import bodyParser from "body-parser";
import { data } from "./data/data.js";
const secret = "test";
dotenv.config();
const app = express();
app.use(express.json());
app.use(helmet());
app.use(helmet.crossOriginResourcePolicy({policy:"cross-origin"}))
app.use(morgan("common"));
app.use(cookieParser())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended:false}))
// app.use(cors({
// origin:["http://localhost:3000/"],
// methods:["GET","POST"],
// credentials: true
// }))
app.use(cors());
const PORT = process.env.PORT || 8080;
// const verifyServer = (req,res,next) =>{
// const token = req.cookies.token;
// if(!token){
// return res.json({Message:"We need token please provide it!"})
// }else{
// jwt.verify(token,secret,(err,decoded) => {
// if(err){
// return res.json({Message:"Authentication Error!"})
// }else{
// req.pravin = decoded.normalize;
// next();
// }
// })
// }
// }
// app.use("/logout",(req,res) => {
// res.clearCookie("token");
// res.json({Message:"Logged Out Successfully!"})
// })
app.use('/api/payment', payment);
app.get("/courses",(req,res) => {
return res.json(data)
})
app.use("/",(req,res) => {
return res.json({name:"success"})
})
mongoose.connect(process.env.MONGO_URL).then(() =>{
app.listen(PORT,() =>{
console.log(`Server is running on port ${PORT}`)
})
}).catch(err =>{
console.log(err,"err")
})