-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.js
69 lines (55 loc) · 1.83 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
var express = require('express');
var app = express();
var https = require('https');
var path = require('path');
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var querystring = require('querystring');
var db = require('./models');
const public = path.join(__dirname, 'public');
const useDB = true;
/**** Setting to false until I set up postgres.
Should be set true if your database is setup.
*********/
app.set('views', path.resolve(__dirname, 'views'));
app.set('view engine', 'pug');
app.set('port', (process.env.PORT || 3000));
app.use(bodyParser.urlencoded({
extended: false
}))
app.use('/', express.static(public));
app.use(express.static(path.resolve(__dirname, 'public')));
app.use(methodOverride(function(req, res){
if (req.body && typeof req.body === 'object' && '_method' in req.body) {
var method = req.body._method;
delete req.body._method;
return method;
}
}));
var adminRoute=require('./routes/admin')(express,app,path,bodyParser,querystring,db);
var buyeroute=require('./routes/buyer')(express,app,path,bodyParser,querystring,db);
var vendorRoute=require('./routes/vendor')(express,app,path,bodyParser,querystring,db);
var productRoute=require('./routes/product')(express,app,path,bodyParser,querystring,db);
var apiRoute = require('./routes/api')(express, app, https, path, bodyParser, querystring, db);
var guestRoute=require('./routes/guest')(express,app,path,bodyParser,querystring,db);
app.use(function(req, res) {
res.status(404).render('404', {subtitle: "Page Not Found"});
})
if(useDB)
{
db.sequelize.sync()
.then(function(){
app.listen(3000,function(){
console.log('Listening on port 3000')
})
})
.catch(function(err){
console.log(err.toString())
})
}
else
{
app.listen(3000,function(){
console.log('Listening on port 3000')
})
}