Menu Home

A HTML nanoserver

There’s nothing complex about the external view of what a HTML server does. In response to a HTTP GET (say) it returns some HTML in the body, at least a single header of ‘Content-Type’ to identify the HTML format, and a status code, eg 200 for success.

This is easily within the capabilities of an Azure Function. For example this HTTP triggered node.js Function:

You can render the HTML in a variety of ways, from the simple ES6 template strings shown in the example, to using a virtual DOM that can render-to-string, for example snabbdom.

Naturally, you can’t use any of the in process web server patterns that rely on persistent in memory state between URLs. Thus you might need to rethink more complex logic.

However, functions support routes and parameters in the URL so you have plenty of flexibility. And for security you can use keys or even JWTs to provide stateless authentication with claims.

One minor issue with usable URLs is caused by the fact that Function URLs are always of the form https://<funcAppName>.azurewebsites/api/<funcName>. There’s none of the default document processing that webservers often provide (ie you they let you omit the …/index[.html] and it will be assumed). So while you can use a DNS CNAME record etc. to map a custom domain to the Azure domain, you remain stuck with URL path as that is used to identify and invoke the function. For example,  https://mydomain.com/myfunc is using easily achievable CNAME and host.json but not something shorter like https://mydomain.com/. Unless, that is is, you are willing to use a URL redirect service. [Thanks to @crandycodes for highlighting this]

Of course, this HTML nanoserver is available on the Azure ‘dynamic’ pay per use plan so is pretty cheap, if not free.

 

 

Categories: Uncategorized

steve@opendirective.com

Leave a Reply