@corejam/base
Version:
A scaffolding for building progressive GraphQL powered jamstack applications
34 lines • 1.08 kB
JavaScript
import { ServerResponse } from "http";
/**
* Currently only a proxy class incase we are inside
* a lambda function and need to parse headers.
*
* Otherwise it just calls super.setHeader and this can be ignored
*/
export default class Response extends ServerResponse {
/**
* Assign the GraphQL Context so we can use it later on
* @param context
*/
constructor(req, context) {
super(req);
if (context && process.env.AWS_EXECUTION_ENV && process.env.AWS_EXECUTION_ENV.includes("AWS_Lambda_")) {
this.context = Object.assign(Object.assign({}, context), { headers: [] });
}
}
/**
* If we are inside a lambda we want to "abuse" the context object
* to write headers in so we can later parse them back out to the lambda event
* structure
*
* @param name
* @param value
*/
setHeader(name, value) {
super.setHeader(name, value);
if (this.context) {
this.context.headers.push({ name, value });
}
}
}
//# sourceMappingURL=Response.js.map