Skip to content

Commit ad2c924

Browse files
authored
Merge pull request #123 from FirebasePrivate/inlined.http-functions
Define functions.HttpsFunction type
2 parents b38ef99 + a888ce6 commit ad2c924

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/cloud-functions.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
import { apps } from './apps';
2424
import * as _ from 'lodash';
25+
import { Request, Response } from 'express';
26+
export { Request, Response };
2527

2628
/** An event to be handled in a developer's Cloud Function */
2729
export interface Event<T> {
@@ -47,6 +49,12 @@ export interface TriggerAnnotated {
4749
};
4850
}
4951

52+
/**
53+
* An HttpsFunction is both an object that exports its trigger definitions at __trigger and
54+
* can be called as a function that takes an express.js Request and Response object.
55+
*/
56+
export type HttpsFunction = TriggerAnnotated & ((req: Request, resp: Response) => void);
57+
5058
/**
5159
* A CloudFunction is both an object that exports its trigger definitions at __trigger and
5260
* can be called as a function using the raw JS API for Google Cloud Functions.

src/providers/https.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
2222

23-
import { TriggerAnnotated } from '../cloud-functions';
24-
import {Request, Response} from 'express';
25-
export {Request, Response};
23+
import { HttpsFunction } from '../cloud-functions';
24+
import { Request, Response } from 'express';
2625

27-
export function onRequest(
28-
handler: (req: Request, resp: Response) => void
29-
): ((req: Request, resp: Response) => void) & TriggerAnnotated {
26+
export function onRequest(handler: (req: Request, resp: Response) => void): HttpsFunction {
3027
// lets us add __trigger without altering handler:
3128
let cloudFunction: any = (req, res) => { handler(req, res); };
3229
cloudFunction.__trigger = {httpsTrigger: {}};

0 commit comments

Comments
 (0)