-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for http events in invoke local (#264)
- Loading branch information
1 parent
2fb939d
commit 446d161
Showing
7 changed files
with
304 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
const express = require('express'); | ||
const http = require('http'); | ||
const net = require('net'); | ||
|
||
// The getReqRes method create an express request and an express response | ||
// as they are created in an express server before being passed to the middlewares | ||
// Google use express 4.17.1 to run http cloud function | ||
// https://cloud.google.com/functions/docs/writing/http#http_frameworks | ||
const app = express(); | ||
|
||
module.exports = { | ||
getReqRes() { | ||
const req = new http.IncomingMessage(new net.Socket()); | ||
const expressRequest = Object.assign(req, { app }); | ||
Object.setPrototypeOf(expressRequest, express.request); | ||
|
||
const res = new http.ServerResponse(req); | ||
const expressResponse = Object.assign(res, { app, req: expressRequest }); | ||
Object.setPrototypeOf(expressResponse, express.response); | ||
|
||
expressRequest.res = expressResponse; | ||
|
||
return { | ||
expressRequest, | ||
expressResponse, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.