-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
43 lines (37 loc) · 1012 Bytes
/
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
'use strict';
const express = require('express');
const _ = require('lodash');
const {
alexaSkill,
assistantAction,
} = require('./src/app');
const config = require('./src/config');
const accountLinkingRoutes = require('./web/routes');
const expressApp = express();
expressApp.use(express.json());
expressApp.use(express.urlencoded({ extended: true }));
expressApp.use(express.static(`${__dirname}/web/public`));
expressApp.set('views', `${__dirname}/web/views`);
expressApp.set('view engine', 'ejs');
const routes = {
'/alexa': alexaSkill,
'/googleAction': assistantAction,
};
if (config.server.hostSkill) {
_.map(routes, (handler, route) => {
expressApp.post(
route,
async (req, res, next) => {
try {
const reply = await handler.execute(req.body);
res.json(reply);
} catch (e) {
next(e);
}
},
);
});
}
expressApp.use(accountLinkingRoutes);
expressApp.listen(config.server.port);
exports.expressApp = expressApp;