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

feat: switch to Azure Functions v4 #177

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

derkoe
Copy link

@derkoe derkoe commented Jun 25, 2024

This switches to the new v4 runtime of Azure functions in Azure Static Webapps

  • remove function.json - it is not needed anymore
  • rename function path to "sk_render" since v4 does not allow the path to start with "__"
  • add @azure/functions to external esbuild options (if not already there) - it's needed by the new runtime

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 #159

Copy link
Owner

@geoffrich geoffrich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is looking pretty good! Just some small comments and requests for clarification. Unit tests are failing too, I think because we're writing some different files.

@@ -2,6 +2,6 @@
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[2.*, 3.0.0)"
"version": "[4.0.0, 5.0.0)"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a external Azure function in this folder that also needs to be converted to the v4 model

]
}
`;
const ssrFunctionRoute = '/api/sk_render';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return ipAddress;
},
platform: {
user: httpRequest.user,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


if (debug) {
context.log(`SK headers: ${JSON.stringify(Object.fromEntries(rendered.headers.entries()))}`);
context.log(`Response: ${JSON.stringify(rendered)}`);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not continue to log the response here?

* */
function toRequest(context) {
const { method, headers, rawBody, body } = context.req;
// because we proxy all requests to the render function, the original URL in the request is /api/__render
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep the comment?

headers: new Headers(headers),
// @ts-ignore
body: httpRequest.body,
duplex: 'half'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why set this property?

const resCookies = [];

headers.forEach((value, key) => {
if (key === 'set-cookie') {
const cookieStrings = set_cookie_parser.splitCookiesString(value);
// @ts-ignore
resCookies.push(...set_cookie_parser.parse(cookieStrings));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is due to a type mismatch on the sameSite property - are we sure the sameSite property returned by set_cookie_parser matches what Azure expects?

Type 'string' is not assignable to type '"Strict" | "Lax" | "None"'

Comment on lines -87 to -93
if (method !== 'GET' && method !== 'HEAD') {
init.body = Buffer.isBuffer(body)
? body
: typeof rawBody === 'string'
? Buffer.from(rawBody, 'utf-8')
: rawBody;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this logic isn't needed any more under the v4 model?

@geoffrich
Copy link
Owner

@derkoe no rush, but please re-request my review on the PR once you've addressed my comments - that way it doesn't get lost in my inbox

@derkoe derkoe force-pushed the feat/azure-functions-v4 branch from 9e297ea to 4cbffd0 Compare November 17, 2024 20:37
@derkoe
Copy link
Author

derkoe commented Nov 17, 2024

@derkoe no rush, but please re-request my review on the PR once you've addressed my comments - that way it doesn't get lost in my inbox

Guess I've addressed all the issues - sorry for the delay. (Also rebase on current main today).

@derkoe derkoe requested a review from geoffrich November 17, 2024 20:42
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 this pull request may close these issues.

Support v4 of azure functions
2 participants