-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
106 lines (81 loc) · 2.96 KB
/
main.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const express = require("express");
const cors = require('cors');
const session = require('express-session');
const passport = require("./Utils/passportConfig");
const config = require('./config.json');
const app = express();
const PORT = process.env.PORT||7400
require('dotenv').config();
const bodyparser = require("body-parser");
app.use(bodyparser.urlencoded({extended:true}));
app.use(bodyparser.json());
//Global MiddleWare
const logging = require("./MiddleWares/Logging");
app.use("/",logging);
// CORS middleware
const corsOptions = {
origin: '*', //allowed origin
optionsSuccessStatus: 200,
methods: ['GET', 'POST', 'PUT', 'DELETE'],
allowedHeaders: ['Content-Type', 'Authorization', 'x-auth-token'],
exposedHeaders: ['x-auth-token', 'remember_me'],
preflightContinue: true,
preflight: function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization, x-auth-token');
res.setHeader('Access-Control-Expose-Headers', 'x-auth-token');
res.setHeader('Access-Control-Allow-Credentials', true);
next();
},
credentials: true,
};
app.options('*', cors(corsOptions));
app.use(cors(corsOptions));
app.use(express.json());
//Facebook , Google and Twitter Middlewares
app.use(session({
secret: config.SECRETKEY,
resave: false,
saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());
// Register Routes
const UserRoutes = require("./Routes/UsersRoutes");
app.use("/api/auth/register",UserRoutes)
//LogIn Routes
const LoginRoutes = require("./Routes/LoginRoutes");
app.use("/api/auth/login",LoginRoutes);
const facebookRoutes = require('./Routes/FacebookRoutes');
app.use('/api/auth/facebook', facebookRoutes);
const twitterRoutes = require('./Routes/TwitterRoutes');
app.use('/api/auth/twitter', twitterRoutes);
const googleRoutes = require('./Routes/GoogleRoutes');
const busboy = require("busboy");
app.use('/api/auth/google', googleRoutes);
//LogOut Routes
const LogoutRoutes = require("./Routes/LogoutRoutes");
app.use("/api/auth/logout",LogoutRoutes);
//Products Routes
const productsRoutes=require('./Routes/ProductsRoutes');
app.use('/api/products', productsRoutes);
// Cart Route
const cartRoutes = require('./Routes/CartRoutes');
app.use('/users', cartRoutes);
// Order Route
const orderRouted = require('./Routes/OrderRoutes');
app.use('/user/order', orderRouted);
// Favourites Route
const favouritesRoutes = require('./Routes/FavouritesRoutes');
app.use('/users', favouritesRoutes);
// Stripe Route
const stripeRoutes = require('./Routes/StripeRoutes');
app.use('/charge', stripeRoutes);
// Revenue Route
const RevenueRoutes = require('./Routes/RevenueRoutes');
app.use('/', RevenueRoutes);
// Chatbot Route
const ChatbotRoutes = require('./Routes/ChatbotRoutes');
app.use('/', ChatbotRoutes);
app.listen(PORT, ()=>{console.log("http://localhost:"+PORT)})