-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
63 lines (51 loc) · 1.79 KB
/
app.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
//
// Copyright (c) 2024 Cisco Systems
// Licensed under the MIT License
//
const debug = require('debug')('autoresponder:app');
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const session = require('express-session');
const chalk = require('chalk');
const app = express();
// Import Integration Options
const params = require('./src/utils/params');
if (!params.publicURL) {
process.stdout.write(`${chalk.red('ERROR: Missing Public URL')}`);
process.exit(1);
}
// Execute Scheduler
require('./src/utils/scheduler');
app.use(express.static(path.join(__dirname, './src/public/')));
app.use('/js', express.static(path.join(__dirname, '/node_modules/jquery/dist')));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(session({
secret: params.sessionSecret,
resave: false,
saveUninitialized: true,
cookie: { maxAge: 120000 },
}));
app.set('views', './src/views');
app.set('view engine', 'ejs');
const oAuthRoutes = require('./src/routes/oAuthRoutes')();
const webhookRoutes = require('./src/routes/webhookRoutes')();
const configRoutes = require('./src/routes/configRoutes')();
app.use('/oauth', oAuthRoutes);
app.use('/webhook', webhookRoutes);
app.use('/config', configRoutes);
// debug(`URL Generated ${params.initiateURL}`);
// Build URL and Display Login Page
app.get('/', (req, res) => {
if (typeof req.session.personId !== 'undefined') {
debug('user logged in, redirecting to config page');
res.redirect('/config');
return;
}
res.render('index', { link: params.initiateURL });
});
// Starts the Cisco Spark Integration
app.listen(params.port, () => {
process.stdout.write(`${chalk.red(`Cisco Webex Teams OAuth Integration started on port: ${chalk.green(`${params.port}`)}`)}\n`);
});