2
votes

I'm using Azure Function App to deploy this sample code:

FUNCTIONS_EXTENSION_VERSION=beta

WEBSITE_NODE_DEFAULT_VERSION=6.5.0

index.js:

module.exports = function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');

if (req.query.name || (req.body && req.body.name)) {
    context.res = {
        // status: 200, /* Defaults to 200 */
        body: "Hello " + (req.query.name || req.body.name)
    };
}
else {
    context.res = {
        status: 400,
        body: "Please pass a name on the query string or in the request body"
    };
}
context.done(); };

function.json:

 {"disabled": false, "bindings": [
{
  "authLevel": "anonymous",
  "type": "httpTrigger",
  "direction": "in",
  "name": "req"
},
{
  "type": "http",
  "direction": "out",
  "name": "res"
}]}

In Local development, everything is ok.

Once deployed, the body of the request POST is 'undefined'

Simple request to call the function: - content-type: application/json

{
"name":"John"
} 

Logs:

{ method: 'POST',
  url: '/api/MyHttpTrigger',
  originalUrl: '/api/MyHttpTrigger',
  headers: 
   { connection: 'close',
     'transfer-encoding': 'chunked',
     accept: 'application/json, text/plain, */*',
     authorization: 'Bearer------',
     expect: '100-continue',
     host: 'dev-we-function-test-api.azurewebsites.net',
     'max-forwards': '10',
     'user-agent': 'axios/0.16.2',
     'x-client-ip': '52.143.137.149',
     'x-client-port': '16079',
     'request-context': 'appId=cid-v1:5443f5a3-02cd-43d3-90d6-1942e07580a1,roleName=Web',
     'request-id': '|rtHs1.ca2e9979_1310.',
     'x-ms-request-id': 'rtHs1',
     'x-ms-request-root-id': '|rtHs1.ca2e9979_1310.',
     'x-waws-unencoded-url': '/api/MyHttpTrigger?code=NhpwrmvOjo809ryOvkzbbBa9B1/Hqj18FoVw9faqq8eKSaoDk4oyeg==',
     'client-ip': '52.143.137.149:16079',
     'is-service-tunneled': '0',
     'x-arr-log-id': 'c2b5dbe9-4193-4b81-821a-8ad2054a1203',
     'disguised-host': 'dev-we-function-test-api.azurewebsites.net',
     'x-site-deployment-id': 'dev-we-function-test-api',
     'was-default-hostname': 'dev-we-function-test-api.azurewebsites.net',
     'x-original-url': '/api/MyHttpTrigger?code=NhpwrmvOjo809ryOvkzbbBa9B1/Hqj18FoVw9faqq8eKSaoDk4oyeg==',
     'x-forwarded-for': '52.143.137.149:16079',
     'x-arr-ssl': '2048|256|C=US, S=Washington, L=Redmond, O=Microsoft Corporation, OU=Microsoft IT, CN=Microsoft IT TLS CA 4|CN=*.azurewebsites.net',
     'x-forwarded-proto': 'https' },
  query: 
   { code: 'NhpwrmvOjo809ryOvkzbbBa9B1/Hqj18FoVw9faqq8eKSaoDk4oyeg==' },
  params: {},
  body: undefined }

Help....

1
Are you using V1 or V2 of functions, and are you running the Windows or Linux version?Connor McMahon
An if you're on v2, what's your WEBSITE_NODE_DEFAULT_VERSION app setting saying?evilSnobu
Yes I'm using V2, WEBSITE_NODE_DEFAULT_VERSION=6.5.0. (Linux version)Christophe PHU

1 Answers

0
votes

Reproduce the error on my side.

Have done some tests to detect the reason.

  • In windows app service plan, works.
  • In linux, C#(csx) HttpTrigger works.
  • Find the node version is 8.9.0 despite default value 6.5.0 in app settings. Use 8.9.0 to test in widows version, also works.

So for js function in linux app service plan(preview), the request body is either lost or failed to parse from my point of view. It seems a language support issue for linux version, because the whole deployment is a template and there's no tips about json data not supported as a request body.

Update

This problem seems resolved, test on runtime 2.0.1.0 (beta) for linux.