facebook twitter hatena line email

「Gcp/Firebase/CloudFunctions/request」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
 
(同じ利用者による、間の5版が非表示)
行1: 行1:
 +
==getでのrequest==
 
functions/index.js
 
functions/index.js
 
<pre>
 
<pre>
exports.log = functions.https.onRequest((request, response) => {
+
exports.log1 = functions.https.onRequest((request, response) => {
 
   const errorlog = request.query['errorlog']
 
   const errorlog = request.query['errorlog']
 
   console.error(errorlog);
 
   console.error(errorlog);
行8: 行9:
 
</pre>
 
</pre>
  
ttps://us-central1-unity-xxxxx.cloudfunctions.net/helloWorld?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 (request.method !== 'POST') {
 +
    response.status(405).send('Method Not Allowed');
 +
    return;
 +
  }
 +
  const errorlog = request.body.errorlog;
 +
  console.error(errorlog);
 +
  response.status(200).send(errorlog);
 +
});
 +
</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', '*');