svelte-adapter-azure-swa
svelte-adapter-azure-swa copied to clipboard
Support v4 of azure functions
Right now the adaptor seems to generate a v3 function sk_render but in my project I'm using v4 functions.
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 (https://github.com/Azure/static-web-apps/issues/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
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.
Thanks for the context Thomas!
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)
I've create a working implementation of v4 API here https://github.com/geoffrich/svelte-adapter-azure-swa/compare/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:
- 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 instaticwebapp.config.jsonfixes this:{ "route": "/about", "rewrite": "/about.html" } - Dynamic routes cannot be linked directly because they result in a redirect-loop. For example if you access
http://localhost:4280/sverdlerunning the app with theswaCLI it seems that SWA is redirecing to/sverdle/. This lands in the Svelte server which redirects to/sverdlean 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)?
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
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.
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
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).
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 https://github.com/derkoe/svelte-adapter-azure-swa/commit/6ad10e025b1467816ad6c04242a7475edee45df7
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 https://github.com/derkoe/sveltekit-azure-swa-test/pull/1)
@geoffrich should I create a PR for the change?
Please do @derkoe !