-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
111 lines (83 loc) · 3.12 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
/*
* Simple Login Registration Node.js App
* This app use Express 3, Mongoose 3, Underscore and MongoDB database
*
*
* Author By Equan Pr.
* http://www.junwatu.com
*
* License : Whatever you want! :D
*/
var express = require("express"),
session = require('express-session'),
morgan = require('morgan'),
bodyParser = require('body-parser'),
cloudinary = require('cloudinary');
methodOverride = require('method-override'),
engines = require('consolidate'),
app = express(),
mongoose = require('mongoose');
var MongoStore = require ( 'connect-mongo' ) ( session );
var config = require('config');
var dbConfig;
var env = process.env.NODE_ENV || 'development';
if ('development' == env) {
dbConfig = config.get('App.dbConfig.url');
app.set('PORT',process.env.PORT);
app.set('IP',process.env.IP);
}else{
dbConfig = "mongodb://"+config.get('App.dbConfig.user')+":"+config.get('App.dbConfig.password')+"@"+process.env.OPENSHIFT_MONGODB_DB_HOST+":"+process.env.OPENSHIFT_MONGODB_DB_PORT+"/localmarket";
app.set('PORT',process.env.OPENSHIFT_NODEJS_PORT);
app.set('IP',process.env.OPENSHIFT_NODEJS_IP);
}
/* ==================================
* MongoDB connection using Mongoose
*/
mongoose.connect(dbConfig);
var db = mongoose.connection;
db.on('connected', function () {
console.log('Connection success database MongoDB.');
dbmessage = 'Connection success database MongoDB. database MongoDB.';
});
db.on('error', function () {
console.error.bind(console, 'Connection error!');
dbmessage = 'MongoDB error!';
});
cloudinary.config(config.get('App.imageStorage'));
app.use(session(
{secret:"secret key",resave: true,
cookie: { maxAge: 24 * 60 * 60 * 1000 },
saveUninitialized: true,
store:new MongoStore({mongooseConnection: db,clear_interval: 3600})}));
app.use(express.static(__dirname + '/public'));
app.use(morgan('dev')); // log every request to the console
app.use(bodyParser.urlencoded({ extended: false })) // parse application/x-www-form-urlencoded
app.use(bodyParser.json()) // parse application/json
app.use(methodOverride());
var multipart = require('connect-multiparty');
app.use(multipart({
uploadDir: './public/data/'
}));
app.engine('html', engines.underscore);
/*
Set views directory. DO NOT set this with the same static directory!.
*/
app.set('views', __dirname + '/src/views');
app.set('view engine', 'html');
/*
Routes
*/
app.use('/vendor', require('./src/routes/vendors'));
app.use('/admin', require('./src/routes/admin'));
app.use('/user', require('./src/routes/users'));
app.use('/customer', require('./src/routes/customers'));
app.use('/shop', require('./src/routes/items'));
app.use('/', require('./src/routes/root'));
app.listen(app.get('PORT'),app.get('IP'),function(){
console.log('Node-Express-MongoDB Dumas App');
console.log('-------------------------------------------');
console.log("Server Port: " + app.get('PORT'));
console.log("Server IP: " + app.get('IP'));
});
var agenda = require('./src/jobs/billing.js')
agenda.agenda.start();