Skip to content

Instantly share code, notes, and snippets.

@jthegedus
jthegedus / CF4F-ES6-2|input.js
Created November 29, 2017 13:23
ES6+ in Cloud Functions for Firebase - input for the last 3 examples
// input - async/awaiy with CommonJS module syntax
const functions = require('firebase-functions');
// returns a string after 5 seconds
const message = () => {
return new Promise(resolve => {
setTimeout(() => {
resolve(`from Babelified Cloud Functions!`)
}, 5000)
})
@jthegedus
jthegedus / CF4F-ES6-2|function05.js
Last active November 29, 2017 13:24
ES6+ in Cloud Functions for Firebase - preset-env to minimally compile async-await
// Babel output - with Babel REPL settings:
// * prettify
// * preset-env Node v6.9
"use strict";
function _asyncToGenerator(fn) {
return function() {
var gen = fn.apply(this, arguments);
return new Promise(function(resolve, reject) {
@jthegedus
jthegedus / CF4F-ES6-2|function04.js
Last active November 29, 2017 13:24
ES6+ in Cloud Functions for Firebase - preset-2015,2016,2017 to compile async/await
// Babel output - with Babel REPL settings:
// * prettify
// * preset-es2015 (es6->es5)
// * preset-es2016 (es7->es6)
// * preset-es2017 (es8->es7)
"use strict";
function _asyncToGenerator(fn) {
return function() {
@jthegedus
jthegedus / CF4F-ES6-2|function03.js
Last active November 29, 2017 13:24
ES6+ in Cloud Functions for Firebase - preset-2015 with async/await (not getting compiled)
// Babel output - with Babel REPL settings:
// * preset-es2015
"use strict";
var functions = require("firebase-functions");
var message = function message() {
return new Promise(function(resolve) {
setTimeout(function() {
resolve("from Babelified Cloud Functions!");
@jthegedus
jthegedus / CF4F-ES6-2|function02.js
Last active November 29, 2017 11:46
ES6+ in Cloud Functions for Firebase - preset-2015 with ES module syntax
// input - using ES module syntax
import * as functions from 'firebase-functions';
export let helloWorld = functions.https.onRequest((req, res) => {
let world = `from Babelified Cloud Functions!`;
res.status(200).send(`Hello ${world}`);
})
// Babel output - with Babel REPL settings:
// * prettify
@jthegedus
jthegedus / CF4F-ES6-2|function01.js
Last active November 29, 2017 11:46
ES6+ in Cloud Functions for Firebase - preset-2015
// input - using CommonJS module syntax
const functions = require('firebase-functions')
module.exports.helloWorld = functions.https.onRequest((req, res) => {
let world = `from Babelified Cloud Functions!`;
res.status(200).send(`Hello ${world}`);
})
// Babel output - with Babel REPL settings:
// * preset-es2015
@jthegedus
jthegedus / CFF-next|firebase.json
Created July 25, 2017 08:42
Cloud Functions for Firebase - NextJS example
{
"hosting": {
"public": "src/public",
"rewrites": [
{
"source": "**/**",
"function": "next"
}
]
},
@jthegedus
jthegedus / CFF-next|package.json
Last active October 28, 2018 07:35
Cloud Functions for Firebase - NextJS example
{
"name": "nextonfirebase",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"install": "yarn build-all",
"next": "yarn build-firebase && cd \"src/app\" && yarn && yarn dev",
"preserve": "yarn build-all",
"serve": "firebase serve",
"predeploy": "yarn build-all",
@jthegedus
jthegedus / CFF-next|functions|index.js
Last active July 21, 2017 15:23
Cloud Functions for Firebase - NextJS example
const functions = require("firebase-functions")
const next = require("next")
var dev = process.env.NODE_ENV !== "production"
var app = next({ dev, conf: { distDir: "next" } })
var handle = app.getRequestHandler()
exports.next = functions.https.onRequest((req, res) => {
console.log("File: " + req.originalUrl) // log the page.js file that is being requested
return app.prepare().then(() => handle(req, res))
@jthegedus
jthegedus / CFF-next|functions|.gitignore
Last active July 25, 2017 05:05
Cloud Functions for Firebase - NextJS example
# src/functions/.gitignore
next