In the previous article “When wechat Applets meet TensorFlow: Server-side Implementation”, we discussed the server-side implementation of wechat applets. Today, I found a problem when DEBUGGING wechat applet, that is: wechat applet requires HTTP requests to use the more secure HTTPS protocol.

Modify Simple TensorFlow Serving

For this I studied Simple TensorFlow Serving: github.com/tobegit3hub… Flask was used for its WEB framework. Flask is fairly easy to add HTTPS support, so I added three parameters:

parser.add_argument(
    "--enable_ssl", default=False, help="If enable RESTfull API over https")
parser.add_argument(
    "--secret_pem", default="secret.pem", help="pem file")
parser.add_argument(
    "--secret_key", default="secret.key", help="key file")
Copy the code

The first parameter specifies whether to enable HTTPS, and the next two parameters are the certificate file name. I have submitted a PR to the original author for this modification, waiting for the merger. Before merging, you can visit github.com/mogoweb/sim… Get the latest code.

The certificate application

I can apply for a free certificate on Aliyun, which is valid for only one year, but it is enough for me. It should be noted that the application certificate on Aliyun is very hidden, and I tried several combinations before the option of free certificate appeared. Because my host is hosted on Aliyun, and my domain name is also using aliyun’S DNS service, I can quickly approve my application and then download the certificate. When downloading the certificate, I selected the certificate for Nginx and downloaded two files: a PEM file and a key file.

Test client

The test client does not need to change the URL from http:// to https://. To do this, I also added a parameter enable_ssl:

  if enable_ssl :
    endpoint = "https://ilego.club:8500"
  else:
    endpoint = "http://ilego.club:8500"
Copy the code

For the complete code, see: github.com/mogoweb/aie…

summary

When you are actually working on a project, you will always encounter unexpected problems, which is far from the experience of reading a book and typing a few demos. At the beginning of the micro channel small program, feel very simple, but do do, found that there are many problems encountered all the way. This is why I often advise novices to do a small project themselves, even if it has no production value, even if it is to modify existing code, but the experience gained in the process is still valuable to the individual.