-
Notifications
You must be signed in to change notification settings - Fork 18
/
server.js
51 lines (44 loc) · 1.68 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
//var hotswap = require('hotswap');
var fs = require('fs');
var path = path = require('path');
var express = require('express');
var alexa = require('alexa-app');
var bodyParser = require('body-parser');
var https = require('https');
var privateKey = fs.readFileSync('./cert/private-key.pem', 'utf8');
var certificate = fs.readFileSync('./cert/certificate.pem', 'utf8');
var credentials = {key: privateKey, cert: certificate,
//requestCert: true, rejectUnauthorized: true
requestCert: true
};
// this code is largely taken from
// https://github.com/matt-kruse/alexa-app-server
// Start up the server
var expressApp = express();
var httpsServer = https.createServer(credentials, expressApp);
var PORT = 443;
expressApp.use(bodyParser.urlencoded({ extended: true }));
expressApp.use(bodyParser.json());
expressApp.set('view engine', 'ejs');
// Register Alexa apps
//register_apps('./','/');
var app = require('./remote.js');
var endpoint = '/remote';
expressApp.post(endpoint,function(req,res) {
var subject = req.connection.getPeerCertificate().subject;
app.request(req.body).then(function(response) {
res.json(response);
},function(response) {
res.status(500).send("Server Error");
});
});
// Configure GET requests to run a debugger UI
expressApp.get(endpoint,function(req,res) {
var subject = req.connection.getPeerCertificate().subject;
res.render('test',{"app":app,"schema":app.schema(),"utterances":app.utterances(),"intents":app.intents});
});
// Serve static files
//expressApp.use(express.static('public_html'));
//expressApp.listen(PORT);
httpsServer.listen(PORT);
console.log("Listening on port "+PORT);