-
Notifications
You must be signed in to change notification settings - Fork 2
/
app antes de spotify.js
282 lines (203 loc) · 7.39 KB
/
app antes de spotify.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
//10 de agosto
'use strict';
require('dotenv').config();
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var exphbs = require('express-handlebars');
var sassMiddleware = require('node-sass-middleware');
var session = require('express-session');
var redisVars = require('./config/config_vars').redis
var redisClient = require('redis').createClient(redisVars.REDIS_URL);
var RedisStore = require('connect-redis')(session)
var Promise = global.Promise || require('promise');
var helpers = require('./lib/helpers');
var config = require('./config/config_vars')
var APLICATION_URL_DOMAIN = config.APLICATION_URL_DOMAIN
var methodOverride = require('method-override');
var fbgraphModule = require('./routes/facebook_graph_module/fb_graph_module');
var index = require('./routes/index');
//var users = require('./routes/users');
var webhook = require('./routes/webhook');
var storeUrl = require('./routes/redirect');
//var ticketSales = require('./routes/event');
var ticketGroups = require('./routes/groups');
var events = require('./routes/tickets-controllers/event.controller');
var ticket_Groups = require('./routes/tickets-controllers/ticketgroup.controller');
//var checkoutBuy = require('./routes/checkout');
var checkoutBuy = require('./routes/tickets-controllers/checkout.controller');
var pay_controller = require('./routes/tickets-controllers/pay.controller');
var creditcard_finish_controller = require('./routes/tickets-controllers/creditcard_finish.controller')
//var payment = require('./routes/pay');
var finish = require('./routes/finish');
var email = require('./routes/email');
var ChatBox = require('./bot/chatbox');
// prueba alexis
//ChatBox.unsetGreetingText(); // Reset Greetings
ChatBox.startButton('Greetings');
ChatBox.greetingText('Pepper automatically finds relevant restaurants & bars for you by learning your habits', 'default');
ChatBox.persistentMenu({
"type": "postback",
"title": "Start again",
"payload": "Greetings"
});
var app = express();
app.listen(3000, function () {
var menu = require('./bot/get_started');
setInterval(function () {
menu.deleteAndCreatePersistentMenu();
}, 1000 * 60);
});
/*
app.use(function(req, res, next) {
res.header('Content-Type','application/vnd.api+json; charset=utf-8');
res.header("Access-Control-Allow-Origin", '*');
res.header('Access-Control-Allow-Methods','POST, GET, PUT, DELETE, OPTIONS');
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Access-Control-Allow-Headers, Authorization, X-Requested-With, Content-Type, Accept, Connection, Content-Length, Cookie, Host, Keep-Alive, Referer, Upgrade, Transfer-Encoding");
next();
});
*/
app.use(function (req, res, next) {
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header("Access-Control-Allow-Origin", "https://botboletos-test.herokuapp.com");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
//############MANEJO DE PLANTILLAS express-handlebars####################
var hbs = exphbs.create({
defaultLayout: 'default',
extname: '.hbs',
partialsDir: [
'views/partials/'
]
});
/*app.engine('.hbs', exphbs({
defaultLayout: 'default',
ext: '.hbs',
}));*/
app.engine('.hbs', hbs.engine);
app.set('view engine', '.hbs');
//############MANEJO DE PLANTILLAS####################
app.use(sassMiddleware({
/* Options */
src: __dirname,
dest: path.join(__dirname, 'public'),
debug: true,
outputStyle: 'compressed',
prefix: '/prefix' // Where prefix is at <link rel="stylesheets" href="prefix/style.css"/>
}));
app.use(logger('dev'));
app.use(bodyParser.json());
var urlencodedParser = app.use(bodyParser.urlencoded({
extended: false
}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
//midleware para ssessions...
var sess = {
name: 'session',
secret: "some secret",
cookie: {
path: '/',
httpOnly: true,
secure: true,
maxAge: 24 * 60 * 60 * 1000,
signed: false
},
resave: false,
saveUninitialized: true,
store: new RedisStore({
host: redisVars.REDIS_HOST,
port: redisVars.REDIS_PORT,
db: 0,
cookie: {
maxAge: (3600 * 1000 * 30)
}, // 30 Days in ms
client: redisClient
})
}
if (app.get('env') === 'production') {
app.set('trust proxy', 1) // trust first proxy
sess.cookie.secure = true // serve secure cookies
}
app.use(session(sess))
app.use(methodOverride());
//app.use(express.static(__dirname + '/public'));
app.use('/dashboard', index);
//app.use('/users', users);
// xxx app.use('/webhook2/', webhook);
var welcome = require('./routes/welcome/welcome')
app.get('/', welcome.welcome);
app.get('/webhook2/', webhook.intitGetFB);
app.post('/webhook2/', webhook.initFBEvents);
app.use('/redirect/', storeUrl);
//app.use('/event/', ticketSales);
app.get('/event/', events.render_events);
app.use('/tickets/', ticketGroups);
app.get('/ticketgroups/:event_id', ticket_Groups.ticketgroup);
//app.use('/checkout/', checkout);
app.post('/checkout/', checkoutBuy.checkout);
app.post('/checkout/paypal_pay/', checkoutBuy.paypal_pay);
app.use('/paypal_success/', checkoutBuy.paypal_success);
app.use('/paypal_cancel/', checkoutBuy.paypal_cancel);
app.post('/pay/', pay_controller.init_pay);
//app.use('/finish/', finish); // finishing checkout / creating orders and payments
app.post('/finish_pay_credit_card/', creditcard_finish_controller.finishCC);
app.get('/auth/', fbgraphModule.auth);
// user gets sent here after being authorized
app.get('/UserHasLoggedIn/', fbgraphModule.UserHasLoggedIn);
app.get('/zuck/', fbgraphModule.zuck);
app.use('/pruebamail/', email);
// catch 404 and forward to error handler
app.use(function (req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
app.use(function (req, res, next) {
if (!req.session) {
return next(new Error('oh no')) // handle error
} else {
console.log("req.session" + req.session)
}
next() // otherwise continue
})
// error handler
app.use(function (err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
function exposeTemplates(req, res, next) {
// Uses the `ExpressHandlebars` instance to get the get the **precompiled**
// templates which will be shared with the client-side of the app.
hbs.getTemplates('shared/templates/', {
cache: app.enabled('view cache'),
precompiled: true
}).then(function (templates) {
// RegExp to remove the ".handlebars" extension from the template names.
var extRegex = new RegExp(hbs.extname + '$');
// Creates an array of templates which are exposed via
// `res.locals.templates`.
templates = Object.keys(templates).map(function (name) {
return {
name: name.replace(extRegex, ''),
template: templates[name]
};
});
// Exposes the templates during view rendering.
if (templates.length) {
res.locals.templates = templates;
}
setImmediate(next);
})
.catch(next);
}
module.exports = app;