Ask Reuben

httpsdispatch

How can I use httpdispatch with https ?

When using httpdispatch, how can I have a Secure Context?

How can I deploy a GWA app to my device without using a Web Server?

When using httpdispatch, your test URL will be of the form http://localhost:6394/demos.html which leads to the demo Genero application http://localhost:6394/ua/r/demo. If you are connecting to that from another device e.g. testing a mobile device, by replacing localhost with the IP address of the machine running httpdispatch, then you will be in degraded mode as it is not a Secure Context.  As discussed here, you will see a red badge on the Settings icon, and a message will appear in the Settings screen about the degraded functionality.

As per the GAS documentation on httpdispatch, you will see that to run using https, you need to start httpdispatch with two additional arguments –cert-file and –cert-key

httpdispatch --cert-file myCert.crt --cert-key myCert-key.key

In this mode, the URLs are now of the form https://localhost:6394/demos.html, https://localhost:6394/ua/r/demo

How can you quickly generate some certificates and keys in order to try this?

The BDL documentation has a section on creating certificates in practise and in particular

It is a little bit tricky to follow but essentially you follow steps 1,2 for creating a certificate.  Then you need to do the 4 steps from the create a root certificate authority, and then come back to execute step 3 from creating a certificate to create your self signed certificate.  (Or you do it in the opposite order of the documentation and create the root certificate authority first so that it is there when you follow the instructions to create a certificate and self sign it)

Having created certificates using the same file names as in the example, you can execute httpdispatch using the following arguments …

httpdispatch --cert-file MyCert.crt --cert-key MyCert.pem

… and this will start httpdispatch using https and hence in a Secure Context.  ( I have created a small script, httpsdispatch that executes httpdispatch with these arguments to save me a bit of typing!.  Maybe one day I will be able to persuade the GAS team to do the same)

Self-signed certificates and httpdispatch are two things you will not likely use in a production environment but in a development environment being able to use httpdispatch with https may be beneficial.  For me that involved trialling our new Genero Web App (GWA) functionality by deploying a Genero Web App onto my phone.  As per the Pre-requisites section in the GWA overview,

The GWA uses Service Workers that require you to run applications with HTTPS activated, or to use localhost.

… so in order to get a GWA application onto my phone, I needed to be using https with a URL similar to https://[ip-address]:6394/gwa/[app-name]/index.html.  Once my GWA app was on my phone, I could turn off Mobile Data, Wifi and verify that the app could continue to run and be able to be started when offline.