Setting up the debug hub for external requests

Set up the debug hub with a new page allowing to start and stop a webserver taking requests from other applications.

Advertisements

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 :

Schermafbeelding 2017-01-21 om 23.04.38.png

Use the id in a jQuery statement to switch the panes when clicked.

Schermafbeelding 2017-01-21 om 23.04.50.png

Make sure the correct file name is returned.

Schermafbeelding 2017-01-21 om 23.04.55.png

Eventually I need to create a new html file :

Schermafbeelding 2017-01-21 om 23.05.04.png

I basically copy pasted the home.html file but I made a few adjustments :

Schermafbeelding 2017-01-21 om 23.20.49.png

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 :

start-server.gif

Let’s test it out.  Start the server and browse to the URL and port the server is started on :

Schermafbeelding 2017-01-21 om 23.23.29.png

and there we go: the result of the app.get function listening to the root of the URL.

Schermafbeelding 2017-01-21 om 23.04.15.png

Cheers!

One thought on “Setting up the debug hub for external requests”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s