0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Cloud Functions

Last updated at Posted at 2019-11-21
bash
mkdir firebase
cd firebase
npm install -g firebase-tools
firebase init
firebase login
  • ロケーションを設定
fbロケーション.png
index.js

const functions = require('firebase-functions');
const admin = require('firebase-admin');
const axios = require('axios');


admin.initializeApp();

const db = admin.firestore();

exports.db = functions.https.onRequest(async (request, response) => {
  const snapshot = await db.collection('users').get();
  const items = snapshot.docs.map(doc => doc.data());
  console.log(items);
  response.send(JSON.stringify(items));
});

exports.query = functions.https.onRequest((request, response) => {
  console.log('query', request.query);
  response.send(JSON.stringify(request.query));
});

exports.html = functions.https.onRequest((request, response) => {
  console.log('query', request.query);
  response.status(200).send(
  `<html>
    <body>
      <div style='color: red'>${JSON.stringify(request.query)}</div>
    </body>
  </html>`
  );
});

exports.schedule = functions.pubsub.schedule('every 1 minutes').onRun((context) => {
  console.log('every 1 minutes');
  return null;
});

exports.axios = functions.https.onRequest(async (request, response) => {
  const { data } = await axios.get('https://xxx.com/query?id=1');
  console.log(data);
  response.send(JSON.stringify(data));
});

bash
firebase deploy --only functions:query,functions:html
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?