-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
153 lines (133 loc) · 5.21 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// set up ===============================================================
require('dotenv').config()
const express = require('express');
const path = require('path');
const port = process.env.PORT || 5000;
const dev = process.env.NODE_DEV !== 'production' //true false
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const logger = require('morgan');
const next = require('next')
const nextApp = next({ dev })
const handle = nextApp.getRequestHandler() //part of next config
var cors = require('cors');
const passport = require('passport');
const cookieParser = require('cookie-parser');
var mail = require('./nodeMailerWithTemp');
var sm = require('sitemap')
require('./middleware/passport')(passport);
console.log('dev = ', dev)
// DB configuration ===============================================================
const dbRoute = process.env.DB_URI;
mongoose.connect(
dbRoute,
{ useNewUrlParser: true }
);
let db = mongoose.connection;
db.once("open", () => console.log("connected to the database"));
db.on("error", console.error.bind(console, "MongoDB connection error:"));
nextApp.prepare().then(() => {
const app = express();
/*var sitemap = sm.createSitemap ({
hostname: 'https://foodiebee.eu',
cacheTime: 600000, // 600 sec - cache purge period
urls: [
{ url: '', changefreq: 'daily', priority: 0.7 },
{ url: '/aboutus', changefreq: 'monthly', priority: 0.3 },
{ url: '/contactus', changefreq: 'monthly', priority: 0.3 },
{ url: '/login', changefreq: 'monthly', priority: 0.3 },
{ url: '/register', changefreq: 'monthly', priority: 0.3 },
{ url: '/termscondition', changefreq: 'monthly', priority: 0.3 },
{ url: '/privacypolicy', changefreq: 'monthly', priority: 0.3 },
{ url: '/caterersignup', changefreq: 'monthly', priority: 0.7 },
]
});*/
// express code here
// (optional) only made for logging and
// bodyParser, parses the request body to be a readable json format
app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(logger("dev"));
app.use(cookieParser());
app.use(passport.initialize());
//app.use(express.static(path.join(__dirname, 'client/build')));
// router files ===============================================================
var authRoutes = require('./routes/auth');
var catererPublishedRoutes = require('./routes/catererPublished');
var catererRoutes = require('./routes/caterer');
var customerRoutes = require('./routes/customer');
var menuPublishedRoutes = require('./routes/menuPublished');
var cartRoutes = require('./routes/cart');
var orderRoutes = require('./routes/order');
var paymentRoutes = require('./routes/payment');
// routes ======================================================================
app.use('/auth', authRoutes);
app.use('/catererPublished', catererPublishedRoutes);
app.use('/caterer', catererRoutes);
app.use('/customer', customerRoutes);
app.use('/menuPublished', menuPublishedRoutes);
app.use('/cart', cartRoutes);
app.use('/order', orderRoutes);
app.use('/payment', paymentRoutes);
app.get('/sitemap.xml', function(req, res) {
sitemap.toXML( function (err, xml) {
if (err) {
return res.status(500).end();
}
res.header('Content-Type', 'application/xml');
res.send( xml );
});
});
const path = require('path');
const options = {
root: path.join(__dirname, '/static'),
headers: {
'Content-Type': 'text/plain;charset=UTF-8',
}
};
app.get('/robots.txt', (req, res) => (
res.status(200).sendFile('robots.txt', options)
));
app.post('/postmessage', (req,res) => {
var bodymsg = req.body
mail.sendCustomerMessageEmail('/templates/customer_message_admin/email.html', bodymsg);
res.status(200).json({});
})
app.get('/menudetail', (req,res) => {
return nextApp.render(req, res, '/MenuDetail')
})
app.get('/login', (req,res) => {
return nextApp.render(req, res, '/Login', req.query)
})
app.get('/register', (req,res) => {
return nextApp.render(req, res, '/Register', req.query)
})
app.get('/checkout/:cartID/:catererID', (req,res) => {
return nextApp.render(req, res, '/CheckOut', { cartID: req.params.cartID, catererID: req.params.catererID })
})
app.get('/userprofile/:userprofilepage', (req,res) => {
var returnquery = req.query
returnquery.userprofilepage = req.params.userprofilepage
return nextApp.render(req, res, '/UserProfile', returnquery)
})
app.get('/forgotpassword', (req,res) => {
return nextApp.render(req, res, '/ForgotPassword')
})
app.get('/resetpassword/:resetPasswordToken', (req,res) => {
return nextApp.render(req, res, '/ResetPassword', { resetPasswordToken: req.params.resetPasswordToken } )
})
app.get('/termscondition', (req,res) => {
return nextApp.render(req, res, '/TermsCondition')
})
app.get('/privacypolicy', (req,res) => {
return nextApp.render(req, res, '/PrivacyPolicy')
})
app.get('*', (req,res) => {
return handle(req,res) // for all the react stuff
})
//start server
app.listen(port, (req, res) => {
console.log( `nextjs server listening on port: ${port}`);
})
})