Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support v4 of azure functions #159

Open
jason-johnson opened this issue Nov 16, 2023 · 11 comments · May be fixed by #177
Open

Support v4 of azure functions #159

jason-johnson opened this issue Nov 16, 2023 · 11 comments · May be fixed by #177
Milestone

Comments

@jason-johnson
Copy link

Right now the adaptor seems to generate a v3 function sk_render but in my project I'm using v4 functions.

@geoffrich geoffrich added this to the 1.0 milestone Nov 19, 2023
@geoffrich
Copy link
Owner

Putting a "help wanted" tag on this. It's something I'd like to get to, but I'm unclear one what the support in SWA is for Azure Functions v4 (Azure/static-web-apps#1139) and I don't have time to dig into the v4 changes right now.

If someone is sufficiently motivated to open a PR for this, I'd be happy to review. The sk_render function code is here: https://github.com/geoffrich/svelte-adapter-azure-swa/blob/main/files/entry.js

@geoffrich geoffrich added the help wanted Extra attention is needed label Jan 3, 2024
@thomasgauvin
Copy link

Support for the v4 Node.js programming model for Static Web Apps' managed functions is still pending, so it may not be worth investigating this yet. We'll likely put out an update when support comes, likely months away.

@geoffrich
Copy link
Owner

Thanks for the context Thomas!

@geoffrich geoffrich added blocked-by-upstream and removed help wanted Extra attention is needed labels Mar 5, 2024
@thomasgauvin
Copy link

Update, after investigations, the rollout of v4 Node.js is trickling through, still needs to be investigated why there remains some functions that don't yet have Node.js v4 functions. I would say this is no longer blocked-by-upstream, as it's slowly rolling out (if you're having issues, open a support issue so we can investigate why your SWA/region doesn't yet have v4 Node.js)

derkoe added a commit to derkoe/svelte-adapter-azure-swa that referenced this issue Jun 23, 2024
* remove function.json - it is not needed anymore
* rename function path to "sk_render" since v4 does not allow the path to start with "__"

See also: https://techcommunity.microsoft.com/t5/apps-on-azure-blog/azure-functions-version-4-of-the-node-js-programming-model-is-in/ba-p/3773541

closes geoffrich#159
@derkoe
Copy link

derkoe commented Jun 23, 2024

I've create a working implementation of v4 API here main...derkoe:svelte-adapter-azure-swa:feat/azure-functions-v4

One issue is still open - I need to call npm install in the api directory (to get the @azure/functions depnendey installed). I'm not sure how to do this.

Everything seems to work like with the current adapter but I found some issues with both that are "blockers" with the "SvelteKit demo app". Theses issues are already present in the current implementation:

  1. the fully static route do not work like /about - those result in a 404. The main issue here is that the static files are generated in the build step and the server code does not know how to render them. Adding an entry to the routes in staticwebapp.config.json fixes this:
     {
       "route": "/about",
       "rewrite": "/about.html"
     }
  2. Dynamic routes cannot be linked directly because they result in a redirect-loop. For example if you access http://localhost:4280/sverdle running the app with the swa CLI it seems that SWA is redirecing to /sverdle/. This lands in the Svelte server which redirects to /sverdle an so on. You can also workaround this by adding a route:
     {
       "route": "/sverdle",
       "rewrite": "/api/sk_render" // "/api/__render" for the current version
     }

@geoffrich any idea? maybe we can use the routed from the builder to construct a good routes array (but how to deal with auth)?

@derkoe
Copy link

derkoe commented Jun 23, 2024

the fully static route do not work like /about - those result in a 404. The main issue here is that the static files are generated in the build step and the server code does not know how to render them.

This seems only an issue locally with the SWA CLI.

Dynamic routes cannot be linked directly because they result in a redirect-loop. For example if you access http://localhost:4280/sverdle running the app with the swa CLI it seems that SWA is redirecing to /sverdle/. This lands in the Svelte server which redirects to /sverdle an so on.

This does not occur on a deployed version but there I get a 500 with the current adapter: https://green-wave-04c808103-preview.westeurope.5.azurestaticapps.net/sverdle

@geoffrich
Copy link
Owner

Thanks for working on this @derkoe!

One issue is still open - I need to call npm install in the api directory (to get the @azure/functions depnendey installed). I'm not sure how to do this.

What breaks if you don't do this? If it's bundling the entry, I wonder if the @azure/functions dep should be marked external.

If both the SWA CLI issues are present in the current implementation, then I wouldn't worry about resolving them as part of the v4 work. At least the full static route issue is already known. The infinite redirect issue also sounds familiar but it's been a bit since I looked at SWA CLI stuff.

@geoffrich
Copy link
Owner

Not sure why you're getting a 500 with the current version of the adapter but my demo app still seems to work: https://polite-desert-00b80111e.2.azurestaticapps.net/sverdle

@derkoe
Copy link

derkoe commented Jun 25, 2024

Not sure why you're getting a 500 with the current version of the adapter but my demo app still seems to work: https://polite-desert-00b80111e.2.azurestaticapps.net/sverdle

Just checked that - it works when I deploy with the GitHub Action (https://green-wave-04c808103.5.azurestaticapps.net/sverdle) but it does not work if I deploy with the SWA CLI 🤷‍♂️ (https://green-wave-04c808103-v2.westeurope.5.azurestaticapps.net/sverdle).

@derkoe
Copy link

derkoe commented Jun 25, 2024

What breaks if you don't do this? If it's bundling the entry, I wonder if the @azure/functions dep should be marked external.

Fixed that with derkoe@6ad10e0

The app works perfectly when deployed with the GitHub Action - here is a demo: https://green-wave-04c808103-1.westeurope.5.azurestaticapps.net/
(the PR for that derkoe/sveltekit-azure-swa-test#1)

@geoffrich should I create a PR for the change?

@geoffrich
Copy link
Owner

Please do @derkoe !

@derkoe derkoe linked a pull request Jun 25, 2024 that will close this issue
derkoe added a commit to derkoe/svelte-adapter-azure-swa that referenced this issue Nov 17, 2024
* remove function.json - it is not needed anymore
* rename function path to "sk_render" since v4 does not allow the path to start with "__"

See also: https://techcommunity.microsoft.com/t5/apps-on-azure-blog/azure-functions-version-4-of-the-node-js-programming-model-is-in/ba-p/3773541

closes geoffrich#159
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants