Had to sls deploy to make sure my status codes and response headers were working appropriately. Unfortunately offline wasn't setting the headers appropriately.
Status codes are being dealt with. See #108 #134, and this PR: #133
But we didn't know response headers were faulty too. Can you display a minimal setup where this happens?
Absolutely, and that's exactly why I posted this issue -- saw those status code related issues :)
Check this out, super bare bones SLS setup: unzip this package and npm install, and then compare sls offline and sls deploy. I primarily test via Postman, but even tested the XHR request via web browser inspector (because I was getting paranoid).
(You'll see in handler.js that I've set a custom header with a status code of 201.)
Perfect, getting back at you soon. Thanks
Having differing response headers between offline and deployed. Running sls-offline v1.0.3
Here are my tests:
service: aws-nodejs # NOTE: update this with your service name
provider:
name: aws
runtime: nodejs4.3
functions:
hello:
handler: handler.hello
events:
- http:
path: users/create
method: get
plugins:
- serverless-offline
handler.js:
'use strict';
module.exports.hello = (event, context, callback) => {
const response = {
statusCode: 200,
body: JSON.stringify({
message: 'Go Serverless v1.0! Your function executed successfully!',
input: event,
}),
};
callback(null, response);
// Use this code if you don't use the http event with the LAMBDA-PROXY integration
// callback(null, { message: 'Go Serverless v1.0! Your function executed successfully!', event });
};
as per the template, the url is: http://--host--/users/create
In chrome when hitting aws, response header looks like this:
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 1709
Connection: keep-alive
Date: Thu, 27 Oct 2016 01:02:38 GMT
x-amzn-RequestId: ...
X-Cache: Miss from cloudfront
Via: 1.1 3c6cd3705576f791e49d58b73a16e8f0.cloudfront.net (CloudFront)
X-Amz-Cf-Id: ...
Hitting the same url on my local serverless-offline host I get:
HTTP/1.1 200 OK
vary: origin
cache-control: no-cache
content-length: 1372
date: Thu, 27 Oct 2016 01:08:35 GMT
X-BACKEND: apps-proxy
Particularly, I'm expecting content-type to be "application/json". The aws GAPI doc indicates this is the default behavior if no response configuration is provided.
Let me know if I can help further.
As of release 3.2.1, status codes and headers are now being simulated appropriately. Thanks @dherault!
Cannot take credit for what @leonardoalifraco did :)
Most helpful comment
Perfect, getting back at you soon. Thanks