azure web app how to organize code and folder structure

53 Views Asked by At

I am developing an azure web app service called emailservice, which is supposed to communicate to a mailbox created in office365 exchange online. The webapp is supposed to retrieve messages form the inbox. I have decided to use Microsoft graph api for this matter.

To be able to have successful call to graph API, I registered the app on Azure. I use client credential flow (i.e., acquireTokenByClientCredential) to get access token and then the usual fetch call with access token and the message. This runs ok. I poll and I receive emails sent in response

To make it more advance, I decided to use change notification provided by Microsoft graph. I need to register the app and then create a subscription. The app registration that I did for email retrieval has the permission required for creating subscription as well.

I have the following questions. Please note that I am using nestjs for development

  1. shall I do another app registration for creating the subscription or can I used the same registered app.a)If latter, then I make a acquireTokenByClientCredential call and get one token for creating the subscription. b)Then I make another acquireTokenByClientCredential call and get one token to make action on message (Mail) resource. c)Please note that the question is whether I need one app registration for each or I can reuse the same app registration. Not sure the question seems silly to experts or not
  2. Putting aside the above question, the service folder structure is like

Project root

---->some files such as package.json and etc

---->src

--------->main.ts and app related type script files

--------->email retrieval endpoint folder

--------------->email retrieval end point related file such as serive and controller and …

---->test

Now my question is what is the best place or perhaps convention for the call to acquireTokenByClientCredential as well as creating subscription.

  1. Shall we do it in one of the files such as main.ts or app.service.ts
  2. Shall we create a separate file in src to take care of this and call it within main.ts or app.service.ts
  3. Shall we do within email service retrieval endpoint either within its corresponding service.ts file or separate file

I would appreciate if you can shed a light on what is convention and what is the best practice as well as if one approach has an advantage over the other one.

0

There are 0 best solutions below