「Gcp/Firebase/CloudFunctions/カスタムクラス」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→別クラス呼び出し) |
(→別クラス呼び出し) |
||
行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'); | + | const circle = require('./circle.js'); // require('circle.js')とか、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)); |
2019年8月6日 (火) 14:46時点における版
別クラス呼び出し
functions/index.js
exports.circle = functions.region('asia-northeast1').https.onRequest((request, response) => { const circle = require('./circle.js'); // require('circle.js')とか、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; };