「Gcp/Firebase/CloudFunctions/request」の版間の差分
提供: 初心者エンジニアの簡易メモ
行1: | 行1: | ||
+ | ==getでのrequest== | ||
functions/index.js | functions/index.js | ||
<pre> | <pre> | ||
行9: | 行10: | ||
ttps://us-central1-unity-xxxxx.cloudfunctions.net/log1?errorlog=hoge | ttps://us-central1-unity-xxxxx.cloudfunctions.net/log1?errorlog=hoge | ||
+ | |||
+ | ==postでのrequest== | ||
+ | functions/index.js | ||
+ | <pre> | ||
+ | exports.log1 = functions.https.onRequest((request, response) => { | ||
+ | if (response.method !== 'POST') { | ||
+ | response.status(405).send('Method Not Allowed'); | ||
+ | return; | ||
+ | } | ||
+ | response.status(200).send(req.errorlog); | ||
+ | console.error(errorlog); | ||
+ | response.status(200).send(req.errorlog); | ||
+ | }); | ||
+ | </pre> |
2019年7月9日 (火) 12:49時点における版
getでのrequest
functions/index.js
exports.log1 = functions.https.onRequest((request, response) => { const errorlog = request.query['errorlog'] console.error(errorlog); response.send("Hello from Firebase!log"); });
ttps://us-central1-unity-xxxxx.cloudfunctions.net/log1?errorlog=hoge
postでのrequest
functions/index.js
exports.log1 = functions.https.onRequest((request, response) => { if (response.method !== 'POST') { response.status(405).send('Method Not Allowed'); return; } response.status(200).send(req.errorlog); console.error(errorlog); response.status(200).send(req.errorlog); });