Last active
March 13, 2019 21:52
-
-
Save mlopezr/3f2465da76ac7d061eeefd3fec005c7c to your computer and use it in GitHub Desktop.
Sample server to run Alexa skill on your machine, to be used with ngrok
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const handler = require('./index').handler; | |
function CreateHandler(handler) { | |
return (req, res) => { | |
handler(req.body, null, (err, result) => { | |
if (err) { | |
return res.status(500).send(err); | |
} | |
return res.status(200).json(result); | |
}); | |
}; | |
} | |
// create server | |
const server = express(); | |
const listener = server.listen(process.env.port || process.env.PORT || 8080, function () { | |
const { address, port } = listener.address(); | |
console.log('%s listening to %s%s', server.name, address, port); | |
}); | |
// parse json | |
server.use(bodyParser.json()); | |
// connect the lambda functions to http | |
server.post("/", CreateHandler(handler)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment