From a995e8e130be8537d94b8e2f591a6cc96285ed00 Mon Sep 17 00:00:00 2001 From: horihiro Date: Wed, 22 Sep 2021 15:11:32 +0900 Subject: [PATCH 1/4] fix status code --- mod.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/mod.ts b/mod.ts index ad37571..ae5c782 100644 --- a/mod.ts +++ b/mod.ts @@ -149,7 +149,25 @@ export class AzureFunctionsWorker { // Merge `context.res` into `context.bindings` // `context.res` is the special property for HTTP response // https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-node?tabs=v2#response-object - if (context.res) context.bindings.res = context.res; + if (!context.bindings.res) { + if (context.res?.status) { + context.res.statusCode = context.res.status; + delete context.res.status; + } + context.bindings.res = context.res; + } + registration.metadata?.bindings?.forEach((bindingDef:any) => { + if (bindingDef.type !== "http" || bindingDef.direction !== "out") return; + if (bindingDef.name === "$return") { + result.statusCode = result.status; + delete result.status; + return; + } + if (!context.bindings[bindingDef.name].status) return + const httpOutBinding = context.bindings[bindingDef.name] + httpOutBinding.statusCode = httpOutBinding.status; + delete httpOutBinding.status; + }); ctx.response.body = { Logs: context.log.logs, From fbba8dc23b4d6191e0d1cf3636632179cdf3dc25 Mon Sep 17 00:00:00 2001 From: horihiro Date: Wed, 22 Sep 2021 15:15:13 +0900 Subject: [PATCH 2/4] try JSON.parse twice --- mod.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/mod.ts b/mod.ts index ae5c782..33afc0d 100644 --- a/mod.ts +++ b/mod.ts @@ -66,6 +66,7 @@ async function parseBody(body: { type: string; value: any }) { function tryJsonParse(input: any) { try { input = JSON.parse(input); + input = JSON.parse(input); } catch { } return input; } From 09a4851e9af6c009db8c9604657d8538b4fb5255 Mon Sep 17 00:00:00 2001 From: horihiro Date: Wed, 22 Sep 2021 15:16:01 +0900 Subject: [PATCH 3/4] Uncomment `url` property n `HttpRequest` interface --- mod.ts | 1 + types.ts | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/mod.ts b/mod.ts index 33afc0d..dbbb565 100644 --- a/mod.ts +++ b/mod.ts @@ -46,6 +46,7 @@ class FunctionHttpRequest implements HttpRequest { headers: { [key: string]: string } = {}; query: { [key: string]: string } = {}; params: { [key: string]: string } = {}; + url = ""; body?: any; rawBody?: any; diff --git a/types.ts b/types.ts index e69a0ef..9677e86 100644 --- a/types.ts +++ b/types.ts @@ -72,10 +72,10 @@ export interface HttpRequest { * HTTP request method used to invoke this function. */ method: HttpMethod | null; - // /** - // * Request URL. - // */ - // url: string; + /** + * Request URL. + */ + url: string; /** * HTTP request headers. */ From 548a4492e7bf679caac4562b40bffa5b5519c1ec Mon Sep 17 00:00:00 2001 From: horihiro Date: Thu, 18 Nov 2021 21:26:05 +0900 Subject: [PATCH 4/4] Remove unnecessary code and dependencies --- deps.ts | 1 - mod.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/deps.ts b/deps.ts index a16859d..88898c9 100644 --- a/deps.ts +++ b/deps.ts @@ -5,5 +5,4 @@ export { move, walk, } from "https://deno.land/std@0.79.0/fs/mod.ts"; -export * from "./worker_deps.ts"; export * as semver from "https://deno.land/x/semver@v1.4.0/mod.ts"; diff --git a/mod.ts b/mod.ts index dbbb565..c01f6cf 100644 --- a/mod.ts +++ b/mod.ts @@ -67,7 +67,6 @@ async function parseBody(body: { type: string; value: any }) { function tryJsonParse(input: any) { try { input = JSON.parse(input); - input = JSON.parse(input); } catch { } return input; }