From 7b61b1633703b1961ea9a27abccb8b45b4bbf590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6berl?= <123199+derkoe@users.noreply.github.com> Date: Mon, 15 Jul 2024 08:40:21 +0000 Subject: [PATCH] convert external function to v4 --- demo/func/HelloWorld/function.json | 16 -------------- demo/func/HelloWorld/index.js | 35 +++++++++++++++++++----------- 2 files changed, 22 insertions(+), 29 deletions(-) delete mode 100644 demo/func/HelloWorld/function.json diff --git a/demo/func/HelloWorld/function.json b/demo/func/HelloWorld/function.json deleted file mode 100644 index 1c1f040..0000000 --- a/demo/func/HelloWorld/function.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "bindings": [ - { - "authLevel": "anonymous", - "type": "httpTrigger", - "direction": "in", - "name": "req", - "methods": ["get", "post"] - }, - { - "type": "http", - "direction": "out", - "name": "res" - } - ] -} diff --git a/demo/func/HelloWorld/index.js b/demo/func/HelloWorld/index.js index bd41adb..4189cc9 100644 --- a/demo/func/HelloWorld/index.js +++ b/demo/func/HelloWorld/index.js @@ -1,13 +1,22 @@ -module.exports = async function (context, req) { - context.log('JavaScript HTTP trigger function processed a request.'); - - const name = req.query.name || (req.body && req.body.name); - const responseMessage = name - ? 'Hello, ' + name + '. This HTTP triggered function executed successfully.' - : 'This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.'; - - context.res = { - // status: 200, /* Defaults to 200 */ - body: responseMessage - }; -}; +const { app } = require('@azure/functions'); + +app.http('httpTrigger1', { + methods: ['GET', 'POST'], + handler: async (req, context) => { + context.log('JavaScript HTTP trigger function processed a request.'); + + let name; + if (req.query.has('name')) { + name = req.query.get('name') + } else { + let body = await req.json(); + name = body.name; + } + + const responseMessage = name + ? 'Hello, ' + name + '. This HTTP triggered function executed successfully.' + : 'This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.'; + + return { body: responseMessage }; + } +});