question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

res.sendFile returning different results when run locally vs in Lambda

See original GitHub issue

The below code returns different results based on running it locally vs running it on Lambda. Locally this returns a javascript file properly formatted. However, when I deploy to Lambda I get a base64 encoded blob that is not readable by my application. I have this set up as a proxy integration with API gateway, so it should not be altering the payload at all, and yet it is. Why is this library (or lambda) forcing a base64 encoded response?

'use strict'
const path = require('path')
const compression = require('compression')
const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const awsServerlessExpressMiddleware = require('aws-serverless-express/middleware')
const app = express()


app.set('view engine', 'pug')
app.use(compression())
app.use(cors())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(awsServerlessExpressMiddleware.eventContext())

app.get('/widget/:widgetId', (req, res) => {
	console.log(req)
	res.setHeader('Content-Type', 'text/javascript')
    res.sendFile(path.join(__dirname, '/widget/bundle.js'), {}, function (err) {
    	if(err) {
    		console.log(err)
    	} else {
    		console.log("no error")
    	}
    })
})

// app.listen(3000, function () {
//   console.log('Example app listening on port 3000!')
// })

module.exports = app

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
brettstackcommented, Apr 1, 2017

Yes, click on your API and then click Binary Support

On Fri, Mar 31, 2017, 7:18 PM JensenTStava notifications@github.com wrote:

Is there a way to do that in the AWS UI?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/awslabs/aws-serverless-express/issues/55#issuecomment-290887135, or mute the thread https://github.com/notifications/unsubscribe-auth/ABy6lxyeV5NI_PWEwWU-YYMSQU8uORvNks5rrbQKgaJpZM4MwOxB .

0reactions
brettstackcommented, May 5, 2017

@JensenTStava did you resolve this? You could try modifying your API Gateway API Binary types to include */* and then redeploy.

Read more comments on GitHub >

github_iconTop Results From Across the Web

res.sendFile returning different results when run locally vs in ...
The below code returns different results based on running it locally vs running it on Lambda. Locally this returns a javascript file ...
Read more >
res.sendFile absolute path - node.js - Stack Overflow
The express.static middleware is separate from res.sendFile , so initializing it with an absolute path to your public directory won't do anything to...
Read more >
res.sendFile - Error: ENOENT but the path is correct-node.js
The problem is that you've defined static file middleware, but then you define a route in front of that that tries to handle...
Read more >
lambda-api - npm
The sendFile() method takes up to three arguments. The first is the file . This is either a local filename (stored within your...
Read more >
Increasing development speed with CDK Watch - AWS
cdk watch makes development faster by monitoring your code and assets for changes and automatically performing the optimal form of deployment ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found