serverless / serverless-kubeless

This plugin enables support for Kubeless within the Serverless Framework.
Apache License 2.0
303 stars 80 forks source link

NodeJs HTTP Response Code is always 200 #180

Closed remacr closed 5 years ago

remacr commented 5 years ago

The kubeless nodejs runtime is always returning HTTP code 200. Besides context is always empty, what is that parameter for?

Expected Behavior

module.exports = {
  hello(event, context) {
    return {'statusCode': 403, 'message': 'Hello world'}
  },
}

curl -i http://localhost/hello, should return:

....
HTTP/1.1 403 Forbidden
....
{"statusCode": 403, "message": "Hello world"}

Current Behavior

curl -i http://localhost/hello, returns:

....
HTTP/1.1 200 OK
....
{"statusCode": 403, "message": "Hello world"}
andresmgot commented 5 years ago

hi @raul-madrigal,

For the case of the NodeJS runtime, you have the value event.extensions.response available. This is the ExpressJS response that will be used. You can use event.extensions.response.status(403); to set the status code.

remacr commented 5 years ago

Thanks @andresmgot, I confirm that works.