Skip to content

Instantly share code, notes, and snippets.

@oprog
Last active February 27, 2019 09:49
Show Gist options
  • Select an option

  • Save oprog/f7761f9c8034c0ee276b01233dd9a6b7 to your computer and use it in GitHub Desktop.

Select an option

Save oprog/f7761f9c8034c0ee276b01233dd9a6b7 to your computer and use it in GitHub Desktop.

Revisions

  1. oprog revised this gist Jan 30, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion alexa-sdk-https-server-how-to.js
    Original file line number Diff line number Diff line change
    @@ -33,7 +33,7 @@ app.post('/alexa/', function (req, res) {

    var httpsServer = https.createServer(credentials, app);

    httpsServer.listen(REST_PORT, SERVER_IP,function () {
    httpsServer.listen(SERVER_PORT, SERVER_IP,function () {
    console.log('Alexa Skill service ready on ' + SERVER_IP+":"+SERVER_PORT+" via https. Be happy!");
    });

  2. oprog revised this gist Nov 5, 2016. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions alexa-sdk-https-server-how-to.js
    Original file line number Diff line number Diff line change
    @@ -12,9 +12,6 @@ var lambda = require('./lambda');
    const SERVER_PORT = 443;
    const SERVER_IP = <YOUR_IP>;

    // lambda mock context
    const ctx = context();

    // SSL Certificate stuff for https
    var privateKey = fs.readFileSync(<PATH TO YOUR privateKey file>, 'utf8');
    var certificate = fs.readFileSync(<PATH TO YOUR certificate file>, 'utf8');
    @@ -27,6 +24,7 @@ app.use(bodyParser.json({ type: 'application/json' }));

    // your service will be available on <YOUR_IP>/alexa
    app.post('/alexa/', function (req, res) {
    var ctx = context();
    lambda.handler(req.body,ctx);
    ctx.Promise
    .then(resp => { return res.status(200).json(resp); })
  3. oprog revised this gist Nov 5, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions alexa-sdk-https-server-how-to.js
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ const express = require('express');
    const https = require('https');
    const fs = require('fs');
    const bodyParser = require('body-parser');
    const context = require('aws-lambda-mock-context');
    const context = require('aws-lambda-mock-context');

    // lambda.js contains the lambda function for Alexa as in https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs
    var lambda = require('./lambda');
    @@ -36,6 +36,6 @@ app.post('/alexa/', function (req, res) {
    var httpsServer = https.createServer(credentials, app);

    httpsServer.listen(REST_PORT, SERVER_IP,function () {
    console.log('Alexa Skill service ready on port ' + SERVER_IP+":"+SERVER_PORT+" via https. Be happy!");
    console.log('Alexa Skill service ready on ' + SERVER_IP+":"+SERVER_PORT+" via https. Be happy!");
    });

  4. oprog renamed this gist Nov 5, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. oprog created this gist Nov 5, 2016.
    41 changes: 41 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    'use strict';

    const express = require('express');
    const https = require('https');
    const fs = require('fs');
    const bodyParser = require('body-parser');
    const context = require('aws-lambda-mock-context');

    // lambda.js contains the lambda function for Alexa as in https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs
    var lambda = require('./lambda');

    const SERVER_PORT = 443;
    const SERVER_IP = <YOUR_IP>;

    // lambda mock context
    const ctx = context();

    // SSL Certificate stuff for https
    var privateKey = fs.readFileSync(<PATH TO YOUR privateKey file>, 'utf8');
    var certificate = fs.readFileSync(<PATH TO YOUR certificate file>, 'utf8');
    var ca = fs.readFileSync(<PATH TO YOUR crt file>).toString();
    var credentials = {key: privateKey, cert: certificate,ca:ca};

    const app = express();

    app.use(bodyParser.json({ type: 'application/json' }));

    // your service will be available on <YOUR_IP>/alexa
    app.post('/alexa/', function (req, res) {
    lambda.handler(req.body,ctx);
    ctx.Promise
    .then(resp => { return res.status(200).json(resp); })
    .catch(err => { console.log(err);//add your error handling stuff })
    });

    var httpsServer = https.createServer(credentials, app);

    httpsServer.listen(REST_PORT, SERVER_IP,function () {
    console.log('Alexa Skill service ready on port ' + SERVER_IP+":"+SERVER_PORT+" via https. Be happy!");
    });