Code16challenge - Azure web app using 16 lines of code


While preparing for the Azure exam, I've noticed a supportive initiative on Facebook to help a little girl collect money for her surgery.  A number of my colleagues have already participated in that action, so I've decided to join as well.

The challenge was to prepare any "program" staying in 16 lines codes, sharing it publicly on the FB, and add the #code16challenge hashtag.

Playing a bit recently with Azure, I've decided to use this opportunity to create a small web app  (nodej.js/npm), set up all required Azure resources, and deploy the app to the cloud  - all in 16 lines of code.

  1. web="code16challenge-siepomaga"
  2. asp="wa2021asp"
  3. rg="code16challengeRg"
  4. npm init -y # Webapp setup
  5. echo $(jq '.scripts.start="node index.js"' package.json) > package.json
  6. echo \
  7. "const http = require('http');\
  8.  http.createServer((req, res) => {\ 
  9.  res.writeHead(200, { 'Content-type': 'text/plain' });\
  10.  res.end('Code Challenge - Sie pomaga'); })\
  11. .listen(process.env.port || 8080);" > index.js
  12. az login # Azure setup
  13. az group create --resource-group $rg --location ukwest
  14. az appservice plan create  -n $asp -g $rg --is-linux  --sku F1 --location ukwest
  15. az webapp up -n $web  -p $asp -g $rg --sku F1 --runtime "NODE:14-lts" --os-type Linux --location ukwest
  16. curl -w "\n%{stdout}" "https://"$web".azurewebsites.net" # ....and check

That's all you need to place your web app  into Azure and the Internet. It's not rocket science, but it's always handy to have something like this working and easy to read. 


If you're interested in the  #code16challenge  action, please find more details below.

Comments

Popular posts from this blog

Podman using Ubuntu WSL2

Automatization of test cases in SCRUM

Azure Synapse - first contact