serverless-express icon indicating copy to clipboard operation
serverless-express copied to clipboard

AWS Serverless Lambda (Angular Site in SSR) - Page content is getting downloaded as octet/steam content type header

Open karishmad opened this issue 4 years ago • 1 comments

We are using vendia aws serverless express package for running the angular app in ssr mode using express to be served from serverless. We upgraded from 3.x to 4.x

Handler Code lambda.js 3.x `const awsServerlessExpress = require('aws-serverless-express'); const server = require('./server/main'); const awsServerlessExpressMiddleware = require('aws-serverless-express/middleware');

const AWSXRay = require('aws-xray-sdk'); AWSXRay.captureHTTPsGlobal(require('http'));

server.app.use(awsServerlessExpressMiddleware.eventContext());

const serverProxy = awsServerlessExpress.createServer(server.app, null);

exports.handler = (event, context) => { // Please do not delete the below console. we waste too much time adding it again, // as per ops there is no other way to get the request to lambda console.log(JSON.stringify(event)); return awsServerlessExpress.proxy(serverProxy, event, context); };

Handler Code lambda.js 4.x `const serverlessExpress = require('@vendia/serverless-express'); const server = require('./server/main');

const AWSXRay = require('aws-xray-sdk'); AWSXRay.captureHTTPsGlobal(require('http'));

const app = server.app;

exports.handler = (event, context) => { console.log('Event', JSON.stringify(event)); console.log('context', JSON.stringify(context)); console.log(JSON.stringify(event)); return serverlessExpress({ app })(event, context); }; `

On checking the site rendering when lambda function is invoked when any page url is hit the content of the page is getting downloaded as content-type set as octet-steam. Could you please suggest and help

karishmad avatar Sep 02 '21 05:09 karishmad

Also seeing this issue. I should add that we're behind an ALB and not an API Gateway. Sadly, it doesn't look like this library supports ALB responses?

EDIT: This looks to be related to multiValueHeaders. I had multi value headers enabled in my target group. Disabling it fixed this probem.

However, I would like the ability to use multi value headers in my target group. So maybe this transforms into a feature request where we can pass in something like { multiValueHeaders: true } as a configuration option. Then, when this library returns the response, instead of settings headers it sets multiValueHeaders with the headers as arrays instead of strings.

I think that would solve the issue.

PLUS: You'd be able to market this as "Added support for multi value headers for ALB" or something 👍

elliottkopp avatar Sep 20 '21 20:09 elliottkopp