@geek-fun/serverless-adapter
Version:
Adapter for web frame work express, koa, springboot to run in serverless function as backend of apigateway cross multi cloud provider like aliyun, huawei
40 lines (39 loc) • 1.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const http_1 = require("http");
const HTTPS_PORT = 443;
const NO_OP = () => void 0;
class ServerlessRequest extends http_1.IncomingMessage {
constructor(request) {
super({
encrypted: true,
readable: false,
remoteAddress: request.remoteAddress,
address: () => ({ port: HTTPS_PORT }),
end: NO_OP,
destroy: NO_OP,
path: request.path,
headers: request.headers,
});
const combinedHeaders = Object.fromEntries(Object.entries({
...request.headers,
'content-length': Buffer.byteLength(request.body ?? '').toString(),
}).map(([key, value]) => [key.toLowerCase(), value]));
Object.assign(this, {
...request,
complete: true,
httpVersion: '1.1',
httpVersionMajor: '1',
httpVersionMinor: '1',
headers: combinedHeaders,
});
this.body = request.body;
this.ip = request.remoteAddress;
this.isBase64Encoded = request.isBase64Encoded;
this._read = () => {
this.push(request.body);
this.push(null);
};
}
}
exports.default = ServerlessRequest;