{"id":21145348,"url":"https://github.com/jsa2/azurefncustomhandlers","last_synced_at":"2026-04-02T02:59:34.022Z","repository":{"id":103264366,"uuid":"426632558","full_name":"jsa2/azureFNcustomHandlers","owner":"jsa2","description":null,"archived":false,"fork":false,"pushed_at":"2021-12-31T08:02:31.000Z","size":150,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"public","last_synced_at":"2025-01-21T07:27:16.538Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jsa2.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-10T13:29:04.000Z","updated_at":"2023-02-01T19:12:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"4a1882f3-c5c0-4aea-be97-5313705f4b2a","html_url":"https://github.com/jsa2/azureFNcustomHandlers","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsa2%2FazureFNcustomHandlers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsa2%2FazureFNcustomHandlers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsa2%2FazureFNcustomHandlers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsa2%2FazureFNcustomHandlers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsa2","download_url":"https://codeload.github.com/jsa2/azureFNcustomHandlers/tar.gz/refs/heads/public","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243589255,"owners_count":20315467,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-20T08:39:39.444Z","updated_at":"2025-12-28T19:25:16.235Z","avatar_url":"https://github.com/jsa2.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Azure Functions custom handler demo for express\r\n\r\n## Solution description\r\nThis is just a demo solution. if you are interested to know more about Azure Functions Custom Handlers , I've previously written a blog [here](https://securecloud.blog/2021/01/04/express-js-middlewares-on-azure-functions-via-custom-handlers/\r\n)\r\n\r\n**Why did I test this?**\r\n\r\n- I am spoiled by the pricing model of Azure Functions, thus I wanted to have consumption based web app for very simple implementations (site load is billed per consumption pricing for functions. With lot of siteloads, this could also become more costly) \r\n- I wanted to test proxying implementation using Azure Functions. There is express router [/proxy](azapp/routes/stream.js) in the project\r\n--- \r\n\r\nIs this supported? (or better, is it recommended 😎 ?) That depends alot. For anything in production I would use different services (Azure App service, Azure Container Apps, Azure Static Web apps etc)\r\n\r\n--- \r\n\r\n![img](azapp/public/images/func.png)\r\n\r\n## Disclaimer\r\nRead [License](#license)\r\n\r\n\r\n## Table of contents\r\n- [Azure Functions custom handler demo for express](#azure-functions-custom-handler-demo-for-express)\r\n  - [Solution description](#solution-description)\r\n  - [- I wanted to test proxying implementation using Azure Functions. There is express router /proxy in the project](#--i-wanted-to-test-proxying-implementation-using-azure-functions-there-is-express-router-proxy-in-the-project)\r\n  - [Disclaimer](#disclaimer)\r\n  - [Table of contents](#table-of-contents)\r\n  - [Prerequisites](#prerequisites)\r\n  - [What is used in the demo](#what-is-used-in-the-demo)\r\n  - [Installation](#installation)\r\n    - [CLI script](#cli-script)\r\n  - [After testing](#after-testing)\r\n  - [License](#license)\r\n\r\n\r\n## Prerequisites \r\n\r\nRequirement | description | Install\r\n-|-|-\r\n✅ Bash shell script | Tested with WSL2 (Ubuntu) on Windows 10 | [CLI script](#cli-script)\r\n✅ [p7zip](https://www.7-zip.org/) | p7zip is  used to create the zip deployment package for package deployment | ``sudo apt-get install p7zip-full`` \r\n✅ AZCLI | Azure Services installation |``curl -sL https://aka.ms/InstallAzureCLIDeb \\| sudo bash``\r\n✅ Node.js runtime 14 | Used in Azure Function, and to create local function config |[install with NVM](https://github.com/nvm-sh/nvm#install--update-script)\r\n✅ Azure Function Core Tools and VScode with Azure Functions extension  | if you want to add new templates) to this function and debug locally |[Install the Azure Functions Core Tools](https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=v3%2Clinux%2Ccsharp%2Cportal%2Cbash%2Ckeda#v2)\r\n\r\n\r\n## What is used in the demo\r\n\r\n- Bootstrap from [W3schools](https://www.w3schools.com/bootstrap/)\r\n- Simple client side .JS [public](azapp/public/javascripts/test.js)\r\n- [Express Generator](https://expressjs.com/en/starter/generator.html)\r\n\r\n## Installation\r\n\r\n1. Deploy via [CLI script](#cli-script)\r\n2. run NPM install for both projects function root, and the custom handler \r\n   ```shell\r\n   npm install\r\n   cd azapp \r\n   npm install \r\n   ``` \r\n3. Run `` func host start --javascript ``\r\n\r\n### CLI script\r\nThe CLI script below will use current subscription context to setup the solution after user has performed \r\n\r\nEnsure you have selected a single subscription context\r\n``` AZ LOGIN; az account set --subscription {subscriptionID} ``` \r\n```shell\r\n#az login --use-device-code\r\n#az account set --subscription 6193053b-408b-44d0-b20f-4e29b9b67394\r\n#Define starting variables\r\nrnd=$RANDOM\r\nfnName=fn-honeyPot-$rnd\r\nrg=RG-FN-$rnd\r\nlocation=westeurope\r\n# You can ignore the warning \"command substitution: ignored null byte in input\"\r\nstorageAcc=storage$(shuf -zer -n10  {a..z})\r\n# Your Public IP address\r\nIPRestriction=82.181.97.241\r\n\r\n# Create Resource Group (retention tag is just example, based on another service)\r\naz group create -n $rg \\\r\n-l $location \\\r\n--tags=\"retention=30d\"\r\n\r\n# Create storageAcc Account \r\nsaId=$(az storage account create -n $storageAcc  -g $rg --kind storageV2 -l $location -t Account --sku Standard_LRS  -o tsv --query \"id\")\r\n\r\nsaConstring=$(az storage account show-connection-string -g $rg  -n  $storageAcc -o tsv --query \"connectionString\")\r\n\r\n## Create Function App\r\naz functionapp create \\\r\n--functions-version 3 \\\r\n--consumption-plan-location $location \\\r\n--name $fnName \\\r\n--os-type linux \\\r\n--resource-group $rg \\\r\n--runtime node \\\r\n--storage-account $storageAcc\r\n#\r\nsleep 10\r\n\r\naz functionapp config access-restriction add --name $fnName \\\r\n--resource-group $rg \\\r\n--ip-address $IPRestriction \\\r\n--priority 1\r\n\r\n# Set to read-only, list variables here you want to be also part of cloud deployment\r\naz functionapp config appsettings set \\\r\n--name $fnName \\\r\n--resource-group $rg \\\r\n--settings scope=$scope  WEBSITE_RUN_FROM_PACKAGE=1 \r\n\r\n#Create ZIP package \r\n7z a -tzip deploy.zip . -r -mx0 -xr\\!*.git -xr\\!*.vscode \r\n\r\n# Force triggers by deployment and restarts\r\naz functionapp deployment source config-zip -g $rg -n $fnName --src deploy.zip\r\nsleep 5\r\naz functionapp restart --name $fnName --resource-group $rg \r\nsleep 20\r\n\r\naz functionapp function show -g $rg -n $fnName --function-name skeleton -o tsv --query invokeUrlTemplate\r\n\r\n\r\n#Limit scaling\r\n#https://weblogs.asp.net/morteza/put-a-limit-on-consumption-based-azure-functions-scaling\r\naz resource update --resource-type Microsoft.Web/sites -g $rg -n $fnName/config/web --set properties.functionAppScaleLimit\r\n\r\n#\r\nrm deploy.zip\r\n\r\n\r\n\r\n# git add .; git commit -m \"exports\"; git push\r\n\r\n```\r\n## After testing\r\n```\r\naz group delete \\\r\n--resource-group $rg \r\n```\r\n\r\n\r\n## License\r\nCopyright 2021 Joosua Santasalo\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsa2%2Fazurefncustomhandlers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsa2%2Fazurefncustomhandlers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsa2%2Fazurefncustomhandlers/lists"}