Tried to use KOAjs for the server-side framwork for the backend processing. It’s a powerful framework with relatively simplified syntax, quite easy to start with. If you have some javascript background, with KOAjs probably will be easier for you to become a full-stacker.
There are some preparation readings below, Pls take a look
So what i am trying to do is
- Front-end
- Ajax call to backend
- Backend to receive parameters to call route53 to create a record
- Upon successful return frontend a result
- Front-end track the result and based on the result to present the result in HTML
Front-end
I am using bootstrap to build a form as below
Ajax call to backend
After the submit button clicked, javascript will be triggered.
function Route53_A_Record (){$.ajax({url:’/api/route53_a_record’,type:’post’,async:false,data:$(‘#route53_a_record’).serialize(),success:function(xhr){document.getElementById(“route53_a_record_status”).innerHTML = ‘Successful’;},error:function(xhr) {document.getElementById(“route53_a_record_status”).innerHTML = ‘Failed’;}});}
Back-end Processing and result return
And Promise needed here is to check the restful-api call result first before return the data back to the front-end.
dm=ctx.request.body.a_domain_name// ctx.request.body function is use to extract the form datavar tasks=await new Promise((resolve,reject)=>{route53.changeResourceRecordSets(params, function(err, data) {if(err){reject(err)}else{resolve(data)}})});console.log(tasks);if (!tasks) {ctx.body= {“Status”:”Failed”}} else {ctx.body= {“Status”:”Successful”}}
Result into HTML
I know it’s a bit ugly, ideally the button css need to track the result and change the text. Yet get it working …. Sia .. 😦
Similarly you can have more functions add-on to your portal…