How to use the firebase-functions.https function in firebase-functions

To help you get started, we’ve selected a few firebase-functions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github firebase / functions-samples / quickstarts / time / functions / index.js View on Github external
const functions = require('firebase-functions');
const dateFormat = require('dateformat');
const cors = require('cors')({origin: true});
// [END import]

// [START all]
/**
 * Returns the server's date. A timestamp is returned by default unless a `format` URL query
 * parameter is specified with which we'll try to format the date.
 *
 * Format must follow the Node dateformat library. See: https://www.npmjs.com/package/dateformat
 *
 * Example format: "yyyy-mm-dd h:MM:ss".
 */
// [START trigger]
exports.date = functions.https().onRequest((req, res) => {
// [END trigger]
  cors(req, res, () => {
    try {
      // [START readQueryParam]
      const format = req.query.format;
      // [END readQueryParam]
      // [START send]
      const now = Date.now();
      if (format) {
        const formattedDate = dateFormat(now, format);
        console.log('Sending Formatted date:', formattedDate);
        res.send(formattedDate);
      } else {
        console.log('Sending Timestamp:', now);
        res.send(now.toString());
      }
github Shyam-Chen / Svelte-Starter / func / index.js View on Github external
import functions from 'firebase-functions';
import admin from 'firebase-admin';

admin.initializeApp(functions.config().firebase);

/**
 * @example POST /addText?text=${text}
 */
export const addText = functions.https.onRequest((req, res) => {
  const { text } = req.query;

  admin.database()
    .ref('/messages')
    .push({ text })
    .then(() => {
      res.status(200).json({ message: 'Text saved.' });
    });
});