Skip to content

Exception: Error: Unexpected request.body type: undefined  #255

Open
@Vikas252

Description

@Vikas252

With the same code of the issue https://github.com/dougmoscrop/serverless-http/issues/252 I'm getting an request.body error which says undefined.

The context parameter log:

bindings: {
req: {
       method: 'GET',
       url: 'http://localhost:7071/api/serverless',
       originalUrl: 'http://localhost:7071/api/serverless',
       headers: [Object],
       query: {},
       params: {},
       body: undefined,
       rawBody: undefined
     }

the only one api im using:

router.get("/api/serverless", (req, res) => {
  res.json("hi")
  console.log("hi");
})

the error:

[2022-10-31T07:15:51.445Z] Executed 'Functions.api' (Failed, Id=b1dad52a-5405-4022-bb81-b8be504b7aab, Duration=152ms)
[2022-10-31T07:15:51.445Z] System.Private.CoreLib: Exception while executing function: Functions.api. System.Private.CoreLib: Result: Failure
[2022-10-31T07:15:51.446Z] Exception: Error: Unexpected request.body type: undefined
[2022-10-31T07:15:51.446Z] Stack: Error: Unexpected request.body type: undefined
[2022-10-31T07:15:51.446Z]     at requestBody (/workspaces/serverless/node_modules/serverless-http/lib/provider/azure/create-request.js:25:11)
[2022-10-31T07:15:51.446Z]     at module.exports (/workspaces/serverless/node_modules/serverless-http/lib/provider/azure/create-request.js:32:18)
[2022-10-31T07:15:51.446Z]     at /workspaces/serverless/node_modules/serverless-http/lib/provider/azure/index.js:8:25
[2022-10-31T07:15:51.446Z]     at Object.module.exports.handlertest (/workspaces/serverless/src/handlers/hello.js:47:25)
[2022-10-31T07:15:51.447Z]     at msg (/workspaces/serverless/node_modules/azure-functions-core-tools/bin/workers/node/dist/src/worker-bundle.js:17323:26)
[2022-10-31T07:15:51.447Z]     at WorkerChannel.invocationRequest (/workspaces/serverless/node_modules/azure-functions-core-tools/bin/workers/node/dist/src/worker-bundle.js:42009:28)
[2022-10-31T07:15:51.447Z]     at ClientDuplexStream.<anonymous> (/workspaces/serverless/node_modules/azure-functions-core-tools/bin/workers/node/dist/src/worker-bundle.js:41779:30)
[2022-10-31T07:15:51.447Z]     at ClientDuplexStream.emit (events.js:400:28)
[2022-10-31T07:15:51.447Z]     at addChunk (internal/streams/readable.js:293:12)
[2022-10-31T07:15:51.447Z]     at readableAddChunk (internal/streams/readable.js:267:9).

I'm also trying to implement and debug as the azure is untested

Extra added line to debug in hello.js :

router.use(compression())
router.use(cors())
router.use(bodyParser.json())
router.use(bodyParser.urlencoded({ extended: true }))

this didnt resolve the issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions