'Does adding Access-Contr-Expose-Headers increase the size of the headers returned?
I work for a large company that is already pushing the boundaries of header size limits on AWS Lambda among other things. If I were to expose additional headers aside from the CORS safe-listed headers, does that increase the size of the headers sent in a response? Reason I'm asking is because Expose makes me think they're already included in the Response, but they are just inaccessible or invisible on the browser/app.
Solution 1:[1]
Your problem is that you treat Node as a synchronous / sequential language.
I recommend that you learn about callbacks (you use it here), Promises and async / await. (And TypeScript by the way)
Fortunately, with node v10 you can easily avoid the pitfalls of async and * callback hell * - using async / await
A modern solution should look similar to:
import { readFile } from 'fs/promises'; //Modern fersion of `fs`
const main = async () => { // modern way to define function (async)
let response = ''; // Variables defined by `var` are available in global context, and may cause problems
response = await readFile('test.txt', {encoding: 'utf8' })
return response
}
try { // `try {} catch() {}` - error handling
console.log(await main())//It will work 90% of the time.
} catch (ex) {
console.error(ex)
}
//If you cannot define an asychronic function then use:
main().then((res) =>{
console.log(res)
//Here you can use `res`
}).catch(ex => console.error(ex)) // error handling
// not here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | bato3 |
