In this article I’ll be setting up the debug hub to take external requests. That’s necessary because I want to be sending messages to the debug hub just like I’m sending messages to the mirror. I want the debug hub to act as a go-between between external applications like the AVS Java client and the mirror, just to control what’s happening.
In order to do so I have gave my Mac a fixed IP address. That way I’ll be able to address the debug hub from over the network.
Next I’ll have to install the express framework in my debug hub project. That’s easy :
sudo npm install express
Next up is some small changes to index.html of the debug hub.
Create an extra section in the sidebar. I call the main section “Alexa”, and the subsection “Debug Server”. Notice how I set the Id as well :
Use the id in a jQuery statement to switch the panes when clicked.
Make sure the correct file name is returned.
Eventually I need to create a new html file :
I basically copy pasted the home.html file but I made a few adjustments :
So what’s going on here?
First of all you can see at the bottom of the page, I changed the caption and the Id’s of the buttons on there. I will use them to start and stop the web server.
Next, I have the jQuery statements in the $(document).ready event handler. They link up the buttons to a callback function. Whenever the start button is clicked it calls a function called startServer() and sets the contents of an <a> tab with id “Status” to a string indicating that the server is started. When the stop button is clicked, the reverse happens.
The startServer and stopServer function are defined above. The startServer function starts an express server by calling the app.listen method, stating it to start at port 3000. The stopFunction closes the server, and pops up an alert.
Above that you can see the initialisation (requiring express, and getting the app object). The server object is there to be referenced using the stopServer function after it has been assigned by the startFunction function.
Lastly there’s the app.get method that’s listening for request on the root (/) of the web server. If a request comes, it will return “hello world”.
See the result in action :
Let’s test it out. Start the server and browse to the URL and port the server is started on :
and there we go: the result of the app.get function listening to the root of the URL.