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
330 stars 56 forks source link

Node JS function v4 #1139

Open abaudhuin opened 1 year ago

abaudhuin commented 1 year ago

Is your feature request related to a problem? Please describe. I'm trying to deploy a function located in /api. I'm using nodeJS and I'm using the new version v4 to define code my function. It looks like it not working. I can't reach my function when using v4 but I can when using v3. The type of function I'm talking about: https://techcommunity.microsoft.com/t5/apps-on-azure-blog/azure-functions-version-4-of-the-node-js-programming-model-is-in/ba-p/3773541

Describe the solution you'd like I would like to be able to use functions v4

Describe alternatives you've considered Maybe it's already possible in some way. But since I don't have any errors I don't know what to look for.

diberry commented 1 year ago

In the portal, I configured the SWA managed API to include the v4 config setting ( "AzureWebJobsFeatureFlags": "EnableWorkerIndexing" )but got an error.

image

When I followed the link, it seems like I'm not able to set the AzureWeb prefixed setting.

image

Perhaps this is the problem. But what is the fix.

offbeatful commented 1 year ago

Any updates to this? The linked issue says that the flag requirement will go away. Any insights on that?

guidoffm commented 1 year ago

I am facing this problem, too. With the 4.x programming model no deployed api is recognized by the Azure portal. When I am trying to access the api I get a 404. The build complains about wrong Node version. So I added a file staticwebapp.config.json with the content

 {
    "platform": {
        "apiRuntime": "node:18"
    }
}

Getting the same error when I am trying to set the setting. Is this needed? Can I set this setting in source code?

guidoffm commented 1 year ago

When I use the command to upload the local settings from VS Code then it says the setting for AzureWebJobsFeatureFlags is excluded.

guidoffm commented 1 year ago

I guess v4 is not supported with SWA yet and both the documentation and the tools are misleading.

offbeatful commented 1 year ago

I was able to run it in West US region.

guidoffm commented 1 year ago

Indeed, this works for me, too, on US West 2. Interesting. But it seems Microsoft does not have so many resources to work on this project.

ameinhardt commented 1 year ago

For development and the time being, I created a simple custom managed v3 http proxy (fetch() with functions request data without host, connection header to path of x-ms-original-url) to a stand-alone v4 functions host. With a "/api/*" rewrite to this proxy function in staticwebapp.config.json it forwards simple requests (and appends code= auth)

fiveisprime commented 1 year ago

Hey there! Sorry for the problems and the lack of communication on my part. I've been working with Dina internally and can provide a bit of an update here.

The V4 functions model is changing to no longer require the environment variables, which will light up SWA support as it rolls out. Right now, it's only been rolled out to West US 2 and it's coming to the other regions over time. I'll have to contact the Functions team to verify the timing, but this is on the way and will continue to light up more regions with support for the V4 model.

I'll update here when I have more concrete information and dates.

thammons commented 1 year ago

I'll update here when I have more concrete information and dates.

Any news on this? :)

v4 is GA! ...but unfortunately I'm not seeing much help from Bing with getting my SWA (with managed functions) to not throw 404's when using the v4 model.

My project's azfunc-v4 branch anxiously awaits your reply XD

balbany commented 1 year ago

I'll update here when I have more concrete information and dates.

Any news on this? :)

v4 is GA! ...but unfortunately I'm not seeing much help from Bing with getting my SWA (with managed functions) to not throw 404's when using the v4 model.

My project's azfunc-v4 branch anxiously awaits your reply XD

+1. Same issue with BYO Function App (v4 results in 404's). Works fine in local dev (with the SWA CLI) of course...

thammons commented 1 year ago

+1. Same issue with BYO Function App (v4 results in 404's). Works fine in local dev (with the SWA CLI) of course...

Took me a while to find it.. but @azure/functions is no longer a devdependancy... and it's hosted!

Doublecheck your settings from the migration guide? https://learn.microsoft.com/en-us/azure/azure-functions/functions-node-upgrade-v4?tabs=v4

balbany commented 1 year ago

+1. Same issue with BYO Function App (v4 results in 404's). Works fine in local dev (with the SWA CLI) of course...

Took me a while to find it.. but @azure/functions is no longer a devdependancy... and it's hosted!

Doublecheck your settings from the migration guide? https://learn.microsoft.com/en-us/azure/azure-functions/functions-node-upgrade-v4?tabs=v4

What do you mean by "it's hosted"? I've got the package as a straight dependency, but I'm wondering if it might be a problem with running from zip... anyway nearly finished recreating everything in West US 2, so will see if that makes a difference...

thammons commented 1 year ago

"It's hosted" meaning it deployed to azure and running/responding as expected.

I'm using Azure functions as the API on a Static Web App (managed) in East US 2, so probably not very relevant to your setup.

shibayan commented 11 months ago

In regions (e.g eastasia) where the Azure Functions Runtime version has been updated to 4.28.2, EnableWorkerIndexing is enabled by default, so we have confirmed that the new programming model Function will work.

However, the APIs on Azure Portal seem to be a little strange at the moment.

gerhardgaugusch-wd commented 3 months ago

Is there an update on this issue? It took me days to figure out the v4 model is simply not supported. My SWA is currently deployed in "Location": "Global" so I guess it won't work until it is rolled out everywhere.