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.
- web="code16challenge-siepomaga"
- asp="wa2021asp"
- rg="code16challengeRg"
- npm init -y # Webapp setup
- echo $(jq '.scripts.start="node index.js"' package.json) > package.json
- echo \
- "const http = require('http');\
- http.createServer((req, res) => {\
- res.writeHead(200, { 'Content-type': 'text/plain' });\
- res.end('Code Challenge - Sie pomaga'); })\
- .listen(process.env.port || 8080);" > index.js
- az login # Azure setup
- az group create --resource-group $rg --location ukwest
- az appservice plan create -n $asp -g $rg --is-linux --sku F1 --location ukwest
- az webapp up -n $web -p $asp -g $rg --sku F1 --runtime "NODE:14-lts" --os-type Linux --location ukwest
- 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
Post a Comment