res.sendFile returning different results when run locally vs in Lambda
See original GitHub issueThe 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:
- Created 6 years ago
- Reactions:1
- Comments:13 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, click on your API and then click Binary Support
On Fri, Mar 31, 2017, 7:18 PM JensenTStava notifications@github.com wrote:
@JensenTStava did you resolve this? You could try modifying your API Gateway API Binary types to include
*/*
and then redeploy.