Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit e342c4b

Browse files
Functions++
1 parent af73927 commit e342c4b

3 files changed

Lines changed: 48 additions & 12 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## Testing your functions locally
2+
> This will also do a `tsc`
3+
4+
$ npm run serve
5+
6+
## Debugging your functions locally
7+
> This will also do a `tsc`
8+
9+
$ npm run debug
10+
11+
## To deploy a new version
12+
$ firebase deploy --only functions
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
{
22
"name": "functions",
3+
"engines": {
4+
"node": "10"
5+
},
36
"scripts": {
47
"lint": "tslint --project tsconfig.json",
58
"build": "tsc",
69
"serve": "npm run build && firebase serve --only functions",
710
"shell": "npm run build && firebase functions:shell",
811
"start": "npm run shell",
912
"deploy": "firebase deploy --only functions",
10-
"logs": "firebase functions:log"
13+
"logs": "firebase functions:log",
14+
"test": "mocha --reporter spec",
15+
"debug": "npm run build && ndb firebase serve"
1116
},
1217
"main": "lib/index.js",
1318
"dependencies": {
14-
"firebase-admin": "~7.0.0",
15-
"firebase-functions": "~2.2.0"
19+
"firebase-admin": "~8.7.0",
20+
"firebase-functions": "~3.3.0"
1621
},
1722
"devDependencies": {
18-
"tslint": "~5.12.1",
19-
"typescript": "~3.3.1"
23+
"chai": "^4.2.0",
24+
"firebase-functions-test": "^0.1.7",
25+
"mocha": "^6.2.2",
26+
"tslint": "~5.20.1",
27+
"typescript": "3.5.3"
2028
},
2129
"private": true
2230
}
Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
11
import * as functions from "firebase-functions";
22

3-
// // Start writing Firebase Functions
4-
// // https://firebase.google.com/docs/functions/typescript
5-
//
63
export const helloWorld = functions.https.onRequest((request, response) => {
7-
response.send("Hello from Firebase!");
4+
response.send(`Hello from Firebase!!! ${request.query.text}`);
85
});
96

107
export const helloWorldJson = functions.https.onRequest((request, response) => {
118
response.json({"message": "Hello from Firebase!"});
129
});
1310

14-
// this is a proper callable function
11+
// this is a callable (from code) function
1512
export const helloName = functions.https.onCall((data, context) => {
1613
return {
17-
message: "Hello: " + data
14+
message: `Hello: ${data}`
1815
}
19-
});
16+
});
17+
18+
19+
/*
20+
// Examples of scheduled functions (these require at least the 'Blaze' plan)
21+
22+
exports.scheduledFunction = functions.pubsub.schedule('every 2 minutes').onRun((context) => {
23+
console.log('This will be run every 2 minutes!');
24+
return null;
25+
});
26+
27+
exports.scheduledFunctionCrontab = functions.pubsub.schedule('5 11 * * *')
28+
.timeZone('America/New_York') // Users can choose timezone - default is America/Los_Angeles
29+
.onRun((context) => {
30+
console.log('This will be run every day at 11:05 AM Eastern!');
31+
return null;
32+
}
33+
);
34+
35+
*/

0 commit comments

Comments
 (0)