├── .gitignore ├── README.md ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # Optional REPL history 33 | .node_repl_history 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # alexa-home-server 2 | 3 | This module allows you to run an [alexa-app-server][server] on a device in your home, such as a Raspberry Pi. Running a server in your home allows you to easily communicate other devices on your local network. 4 | 5 | ## Installation 6 | 7 | ```sh 8 | npm install alexa-home-server --save 9 | ``` 10 | 11 | ## Usage 12 | 13 | ```javascript 14 | // index.js 15 | require('alexa-home-server').start({ 16 | server_root: __dirname, 17 | port: 4000 18 | }); 19 | ``` 20 | 21 | ```sh 22 | $ node index.js 23 | Listening on HTTP port 4000 24 | Tunnel URL: https://czceoztype.localtunnel.me 25 | ``` 26 | 27 | ## Options 28 | 29 | This module accepts all options provided by [alexa-app-server][server], with a few additions: 30 | 31 | ```javascript 32 | require('alexa-home-server').start({ 33 | // A string value requesting a specific subdomain on the proxy server. Note: You may not actually receive this name depending on availablily. 34 | subdomain: 'some-subdomain', 35 | 36 | // Proxy to this hostname instead of localhost. This will also cause the Host header to be re-written to this value in proxied requests. 37 | localhost: 'localhost', 38 | 39 | // A callback that is invoked after the network tunnel has been opened 40 | onTunnelStart: function (tunnel) { 41 | console.log('Tunnel URL: %s', tunnel.url); 42 | }, 43 | 44 | // A callback that is invoked if an error occurs while opening a tunnel 45 | onTunnelError: function (err) { 46 | console.error('Tunnel Error: %s', err.message); 47 | } 48 | }); 49 | ``` 50 | 51 | ## Resources 52 | 53 | + [alexa-app][app] 54 | + [alexa-app-server][server] 55 | + [localtunnel][localtunnel] 56 | 57 | [app]: https://github.com/alexa-js/alexa-app 58 | [server]: https://github.com/alexa-js/alexa-app-server 59 | [localtunnel]: https://github.com/localtunnel/localtunnel 60 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var Server = require('alexa-app-server'); 2 | var localtunnel = require('localtunnel'); 3 | 4 | var defaults = { 5 | port: process.env.port || 80, 6 | 7 | onTunnelStart: function (tunnel) { 8 | console.log('Tunnel URL: %s', tunnel.url); 9 | }, 10 | 11 | onTunnelError: function (err) { 12 | console.error('Tunnel Error: %s', err.message); 13 | } 14 | }; 15 | 16 | function HomeServer (serverConfig) { 17 | var config = Object.assign({}, defaults, serverConfig); 18 | 19 | this.start = function () { 20 | localtunnel(config.port, { 21 | subdomain: config.subdomain, 22 | local_host: config.localhost 23 | }, function (err, info) { 24 | if (err) { 25 | config.onTunnelError(err); 26 | } else { 27 | config.onTunnelStart(info); 28 | } 29 | }); 30 | 31 | return new Server(config).start(); 32 | }; 33 | } 34 | 35 | HomeServer.start = function (config) { 36 | var homeServer = new HomeServer(config); 37 | homeServer.start(); 38 | return homeServer; 39 | }; 40 | 41 | module.exports = HomeServer; 42 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "alexa-home-server", 3 | "version": "1.0.0", 4 | "description": "Self-host an Alexa app server", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Ray Zane", 10 | "license": "ISC", 11 | "dependencies": { 12 | "alexa-app-server": "^2.2.4", 13 | "localtunnel": "^1.8.1" 14 | }, 15 | "devDependencies": {}, 16 | "repository": { 17 | "type": "git", 18 | "url": "git+https://github.com/alexa-js/alexa-home-server.git" 19 | }, 20 | "keywords": [ 21 | "alexa", 22 | "app", 23 | "server", 24 | "home" 25 | ], 26 | "bugs": { 27 | "url": "https://github.com/alexa-js/alexa-home-server/issues" 28 | }, 29 | "homepage": "https://github.com/alexa-js/alexa-home-server#readme" 30 | } 31 | --------------------------------------------------------------------------------