{"id":91152,"date":"2021-05-18T17:30:00","date_gmt":"2021-05-18T17:30:00","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/?p=91152"},"modified":"2021-05-17T19:18:15","modified_gmt":"2021-05-17T19:18:15","slug":"azure-static-web-apps-bring-your-own-function-byof","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/blogs\/azure-static-web-apps-bring-your-own-function-byof\/","title":{"rendered":"Azure Static Web Apps: Bring Your Own Function (BYOF)"},"content":{"rendered":"<p>Azure technologies evolve so fast sometimes we lose track of what\u2019s happening. One day, a simple technology is created, on the next day, it becomes something huge, in a blink of an eye. I\u2019m not even sure if my recollection of the story will be correct.<\/p>\n<p>The launch of the GA version of <strong>Static Web Apps<\/strong>, on this last May 12, brought a very interesting new feature and made me get out my data-silo to study and write about it.<\/p>\n<p>The first time I heard about static web sites was in Microsoft Build last year, MS Build 2020. It was (and still is) a feature linked to storage accounts. When enabled, it creates a special container called $web and exposes it as a website with no server technology, only client-side development.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"717\" height=\"547\" class=\"wp-image-91153\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/05\/word-image-75.png\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>This was already very good, but Microsoft decided to go beyond and create the <strong>Static Web App<\/strong>. A <strong>Static Web App<\/strong> is a site with client code but can also include API\u2019s. It\u2019s directly linked with github actions that will define the deployment for the static site content and the API functions in many different languages.<\/p>\n<p>In a static web app the storage is underneath. We don\u2019t need to take care of it. The API\u2019s are deployed using <strong>Azure Functions<\/strong> architecture, but not visible for us on the portal, only accessible to the static web app. The Azure Function architecture is used underneath with docker, but we don\u2019t need to mind too much about this.<\/p>\n<p><strong>New Feature:<\/strong> We can map existing Azure Functions from any of our subscriptions to the API path (usually <em>\/API<\/em>) inside the static web app.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1053\" height=\"662\" class=\"wp-image-91154\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/05\/word-image-76.png\" \/><\/p>\n<h2>Static Web Site<\/h2>\n<p>On a static website, you can implement any client-side framework as long it has no server-side dependency. These frameworks can make calls azure functions without many problems.<\/p>\n<p>However, the front-end application is in one domain, the azure function is in a different domain. This brings security configuration details such as <em>CORS<\/em>. Both pieces, front-end and functions, are independently managed.<\/p>\n<h2>Static Web Apps &#8211; Before<\/h2>\n<p>The <strong>SWA<\/strong> allowed us to create <em>API\u2019s<\/em> together the App and the deployment tasks would handle them. Internally, it uses the Azure Functions architecture, but we don\u2019t need to handle them.<\/p>\n<p>The <em>API\u2019s<\/em> will be in the same web domain, as if they are inside a folder such as <em>\u201c\/API\u201d<\/em>, but internally the <strong>Static Web Apps<\/strong> system is handling them using docker and we don\u2019t need to know too much about it.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"428\" height=\"353\" class=\"wp-image-91155\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/05\/word-image-77.png\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>However, the <em>API\u2019s<\/em> created inside a static web app can\u2019t be accessed outside the App. They don\u2019t become real Azure Functions and can\u2019t even be shared between different Apps<\/p>\n<p>You still can access <strong>Azure Functions<\/strong>, but under the same limitations as in a static web site<\/p>\n<p>&nbsp;<\/p>\n<h2>Static Web Apps &#8211; Now<\/h2>\n<p>The new feature is simple: Bring Your Own Azure Function (<strong><em>BYOF<\/em><\/strong> ?)<\/p>\n<p>The Static Web App will host the static files and the existing Azure Functions will be mapped as if they were a folder inside the Static Web App<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1146\" height=\"453\" class=\"wp-image-91156\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/05\/word-image-78.png\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"711\" height=\"414\" class=\"wp-image-91157\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/05\/word-image-79.png\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"754\" height=\"279\" class=\"wp-image-91158\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/05\/word-image-80.png\" \/><\/p>\n<p>Here are the advantages:<\/p>\n<ul>\n<li>The functions can be re-used in many Apps and different scenarios<\/li>\n<li>The function is called in the same domain context, simplifying the management of CORS, sessions, cookies and so on<\/li>\n<li>Following the micro-services architecture, the Azure Functions are not tied with the UI<\/li>\n<\/ul>\n<p>Limitations:<\/p>\n<ul>\n<li>It only works on standard plan, not on the free plan<\/li>\n<li>We can link only a single function app, we can\u2019t mix different function apps<\/li>\n<li>At this moment, it only works in production environment<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"868\" height=\"122\" class=\"wp-image-91159\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/05\/word-image-81.png\" \/><\/p>\n<h2>Where you can Start<\/h2>\n<ul>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/static-web-apps\/overview?WT.mc_id=AZ-MVP-4014132\">What is Static Web App<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/static-web-apps\/get-started-portal?tabs=vanilla-javascript&amp;WT.mc_id=AZ-MVP-4014132\">Building the Static Web App in the Azure Portal<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/static-web-apps\/local-development?WT.mc_id=AZ-MVP-4014132\">Setup local development for Static Web Apps<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/static-web-apps\/getting-started?tabs=vanilla-javascript&amp;WT.mc_id=AZ-MVP-4014132\">Create your first Static Web App with no framework<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/static-web-apps\/getting-started?tabs=angular&amp;WT.mc_id=AZ-MVP-4014132\">Create your first Static Web App with Angular<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/static-web-apps\/functions-bring-your-own?WT.mc_id=AZ-MVP-4014132\">Bring Your Own Functions to Static Web Apps<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/static-web-apps\/?WT.mc_id=AZ-MVP-4014132\">Azure Static Web Apps Documentation<\/a><\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>We have one new method to deploy static web apps, breaking the front-end from the back-end. The new method has new advantages to offer.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Azure technologies evolve so fast sometimes we lose track of what\u2019s happening. One day, a simple technology is created, on the next day, it becomes something huge, in a blink of an eye. I\u2019m not even sure if my recollection of the story will be correct. The launch of the GA version of Static Web&#8230;&hellip;<\/p>\n","protected":false},"author":50808,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[143560,5364,5336,143561],"coauthors":[6810],"class_list":["post-91152","post","type-post","status-publish","format-standard","hentry","category-blogs","tag-app-service","tag-azure","tag-cloud","tag-static-web-apps"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/91152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/50808"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=91152"}],"version-history":[{"count":1,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/91152\/revisions"}],"predecessor-version":[{"id":91160,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/91152\/revisions\/91160"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=91152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=91152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=91152"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=91152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}