「Gcp/Firebase/CloudFunctions/request」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→postでのrequest) |
|||
(同じ利用者による、間の2版が非表示) | |||
行15: | 行15: | ||
<pre> | <pre> | ||
exports.log1 = functions.https.onRequest((request, response) => { | exports.log1 = functions.https.onRequest((request, response) => { | ||
− | if ( | + | if (request.method !== 'POST') { |
response.status(405).send('Method Not Allowed'); | response.status(405).send('Method Not Allowed'); | ||
return; | return; | ||
} | } | ||
+ | const errorlog = request.body.errorlog; | ||
console.error(errorlog); | console.error(errorlog); | ||
− | response.status(200).send( | + | response.status(200).send(errorlog); |
+ | }); | ||
</pre> | </pre> | ||
+ | |||
+ | ==finished with status code: 304エラーが出る対応== | ||
+ | response.set('Access-Control-Allow-Origin', '*'); |
2021年3月4日 (木) 17:11時点における最新版
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 (request.method !== 'POST') { response.status(405).send('Method Not Allowed'); return; } const errorlog = request.body.errorlog; console.error(errorlog); response.status(200).send(errorlog); });
finished with status code: 304エラーが出る対応
response.set('Access-Control-Allow-Origin', '*');