microsoft / vscode-azurestaticwebapps

Azure Static Web Apps extension for VS Code
https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurestaticwebapps
MIT License
86 stars 33 forks source link

Create SWA + managed API from Advanced creation steps? #753

Open diberry opened 1 year ago

diberry commented 1 year ago

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?

nturinski commented 1 year ago
diberry commented 1 year ago

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

nturinski commented 1 year ago

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.

diberry commented 1 year ago

@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.

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?

nturinski commented 1 year ago

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.