vscode-azurestaticwebapps icon indicating copy to clipboard operation
vscode-azurestaticwebapps copied to clipboard

Create SWA + managed API from Advanced creation steps?

Open diberry opened this issue 3 years ago • 5 comments

How can I create a SWA with managed API from the advanced creation steps? The steps don't ask me where myAPI is or if I want managed or bring my own. Talking to @craigshoemaker, this should be possible. If it isn't possible but only add managed identity afterward - is that step something that happens in VSCode via interactive steps, in portal, or only by editing the yaml action?

diberry avatar Oct 21 '22 15:10 diberry

  • There is no managed API create step during app creation. If the API already exists during creation, we detect it and add the directory to your yaml file.
  • If you need to create one aftwards, you can click here to add a new HTTP trigger, and then commit, and push that code to your repo. image
  • We currently don't support "Bring Your Own Function" right now. I believe that is something that can be done through the portal.
  • Adding managed identities is has to be done through the portal. You may have to update your azure_static_web_apps_api_token property in the yaml file, but I haven't confirmed that.

nturinski avatar Oct 26 '22 22:10 nturinski

@nturinski how do you detect the API? Literally an api folder under the client folder?

diberry avatar Oct 27 '22 01:10 diberry

It happens right here: https://github.com/microsoft/vscode-azurestaticwebapps/blob/9784ffc9e6fc40a39eca3730b6f97c41847e4535/src/commands/createStaticWebApp/tryGetApiLocations.ts

We are looking for a host.json in the root of their project.

nturinski avatar Oct 27 '22 16:10 nturinski

@nturinski @craigshoemaker

I finally have a repro that I think you might agree is a bug. The Cog Search JS sample repo has a dir structure such as:

/quickstart
/search-website-functions-v4
  /client
  /api
/search-website

The search-website-functions-v4 folder is the updated SWA + API app I'm trying to deploy. The search-website is the older version that I intend to delete once the new sample and content are published.

I fork the repo, then clone my fork and open VSCode at the base of the repo. I create a SWA app using the extension. I use the Advanced version of creation but I'm not sure that is necessary any more.

  • free pricing tier
  • build present is 'custom' so I set the client and api folders inside of search-website-functions-v4
  • for the location of the application (client) code I enter '/search-website-functions-v4/client'
  • for the location of the api (function) code I need to enter '/search-website-functions-v4/api' but the extension won't let me. One of the preset defaults has a backward slash instead of forward 'search-website-functions-v4\api'. image

BUG: The default URL has the wrong slash and won't let me enter the correct one. CONSEQUENCE: It creates an action file with that incorrect slash and as a result doesn't find the APIs. Once I edit the action to use the forward slash, the APIs are listed in the functions for the SWA in the portal.

image

How do I use the extension and enter the correct subfolder but sibling to client location without having to then correct the action file?

diberry avatar Oct 27 '22 21:10 diberry

Thanks for the very in-depth investigation, @diberry! This is very helpful and I definitely agree, is a bug. We should be using posix to make sure that the directory is always using / rather than being OS dependent.

Unfortunately, I think that the only workaround is to edit the workflow file directly.

We have logic to use the detected API folder automatically without giving the user an option to enter the value manually. The only way to input manually would be to remove the API folder from your directory which isn't ideal.

nturinski avatar Oct 31 '22 19:10 nturinski