Azure / static-web-apps

Azure Static Web Apps. For bugs and feature requests, please create an issue in this repo. For community discussions, latest updates, kindly refer to the Discussions Tab. To know what's new in Static Web Apps, visit https://aka.ms/swa/ThisMonth
https://aka.ms/swa
MIT License
322 stars 54 forks source link

SWA and APIM on local env #1270

Open bitsmakerde opened 11 months ago

bitsmakerde commented 11 months ago

Hi together,

I've set up an SWA and transitioned the functions connection from a standalone function to API Management. This configuration works seamlessly on Azure. However, I'm facing challenges replicating this setup for my local development environment.

I have two Azure functions:

For API Management (APIM), I've routed these functions as:

My question is: How can I run both functions locally, retaining the same endpoint structure as in APIM? Alternatively, is there a possibility that my method of connecting the function to APIM was not set up correctly?

I appreciate your assistance.

Thank you

Tcsekhar74 commented 11 months ago

Looks like Microsoft doesn't support developing SWA locally.

Here is the official response from Microsoft when I asked the same question:

Hi Chandra,

Hope my previous message did not confuse you.

We wanted to clarify that Azure Static Web App is a proprietary implementation that is only available on Azure, not in any ways you can obtain an exact replica locally. We were helping you to emulate SWA's behavior locally. The SWA CLI is also an emulator project and never meant to be a replica of SWA. About SWA CLI | Static Web Apps CLI (azure.github.io) image

Developing locally is not a feature of SWA, so there is no documentation that provide an established way of “SETTING UP LOCAL DEVELOPMENT”. Local development is fully controlled by users.

Please let us know if you have any questions or concerns over this clarification. Our teams will check what we are able to do for you.

Best regards,

Liam Ma Azure PaaS Support Engineer Azure - App Service Office Hours: T-F 9:00 - 18:00 UTC+8, S 7:00 - 16:00 UTC+8

bitsmakerde commented 11 months ago

@Tcsekhar74

Thank you for your answer.

But I want use the swa tools do it, because apim is fully supported from swa. So I think here should be a way to use it local. If azure call this an emulation is fine for me. But I can't test my app local with swa, because the apim is not emulated by swa. Or I don't find it.

Tcsekhar74 commented 11 months ago

SWA won't be able to emulate the APIM but you will be able to install docker and have a locally hosted APIM running on your local instance. I am able to bind the locally hosted APIM endpoint to the SWA as the backend on my local. But when it starts, it doesn't pass the Subscription key to the locally hosted APIM and hence it doesn't let the SWA/Client see the endpoint.

https://www.youtube.com/watch?v=b_6LTOdKU_4

When I requested for any documentation which shows me how to setup the locally hosted APIM link to the locally hosted SWA, I got a response saying that SWA local development is not supported by microsoft. I did not expect this response from Microsoft.

bitsmakerde commented 11 months ago

@Tcsekhar74

Ok Thank you. How are you develop your app? Or you stop to use swa? Because a local static is impossible?

Ehen you send your request, give microsoft a solution for a working way how to develop in your setup? Like a tunnel to the azure?

thomasgauvin commented 11 months ago

Hi @Tcsekhar74 @bitsmakerde,

You can use the SWA CLI to develop locally with a static site and any local backend (be it Function App, app server (express, .NET Core, etc.) and APIM). The main caveat is that this local backend cannot have authentication blocking access. This should be how your local development is configured.

To do so, run your APIM locally without authentication. Then, use the SWA CLI with the app_devserver_url pointing to your APIM instance.