「Gcp/Firebase/CloudFunctions/カスタムクラス」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→別クラス呼び出し) |
(→別function呼び出し) |
||
(同じ利用者による、間の2版が非表示) | |||
行3: | 行3: | ||
<pre> | <pre> | ||
exports.circle = functions.region('asia-northeast1').https.onRequest((request, response) => { | exports.circle = functions.region('asia-northeast1').https.onRequest((request, response) => { | ||
− | const circle = require('./circle.js'); // require('circle.js')とか、require('circle')の記述はだめだった。 | + | const circle = require('./circle.js'); // require('circle.js')とか、require('circle')とか、require('/circle')の記述はだめだった。 |
response.send('The area of a circle of radius 4 is ' | response.send('The area of a circle of radius 4 is ' | ||
+ circle.area(4)); | + circle.area(4)); | ||
行18: | 行18: | ||
return PI * r * r * r; | return PI * r * r * r; | ||
}; | }; | ||
+ | </pre> | ||
+ | |||
+ | ==別function呼び出し== | ||
+ | <pre> | ||
+ | function sum(){ | ||
+ | return 1 + 2; | ||
+ | } | ||
+ | exports.sum = functions.region('asia-northeast1').https.onRequest((request, response) => { | ||
+ | response.send('sum ' | ||
+ | + sum()); | ||
+ | }); | ||
</pre> | </pre> | ||
==function分割== | ==function分割== | ||
https://uyamazak.hatenablog.com/entry/2018/10/22/113000 | https://uyamazak.hatenablog.com/entry/2018/10/22/113000 |
2019年8月7日 (水) 14:44時点における最新版
別クラス呼び出し
functions/index.js
exports.circle = functions.region('asia-northeast1').https.onRequest((request, response) => { const circle = require('./circle.js'); // require('circle.js')とか、require('circle')とか、require('/circle')の記述はだめだった。 response.send('The area of a circle of radius 4 is ' + circle.area(4)); });
functions/circle.js
var PI = Math.PI; exports.area = function (r) { return PI * r * r; }; exports.cube = function (r) { return PI * r * r * r; };
別function呼び出し
function sum(){ return 1 + 2; } exports.sum = functions.region('asia-northeast1').https.onRequest((request, response) => { response.send('sum ' + sum()); });