Skip to content

Instantly share code, notes, and snippets.

@jthegedus
jthegedus / CF4F-graphql|firebaseFunctions|graphql|data|resolver.js
Last active October 9, 2017 14:39
Cloud Functions for Firebase - GraphQL Server - /functionsES6/graphql/data/resolvers.js
const authors = [
{ id: 1, firstName: "Tom", lastName: "Coleman" },
{ id: 2, firstName: "Sashko", lastName: "Stubailo" }
]
const posts = [
{ id: 1, authorId: 1, title: "Introduction to GraphQL", votes: 2 },
{ id: 2, authorId: 2, title: "GraphQL Rocks", votes: 3 },
{ id: 3, authorId: 2, title: "Advanced GraphQL", votes: 1 }
]
@jthegedus
jthegedus / CF4F-express|functionsES6|index-02.js
Last active October 9, 2017 13:51
Cloud Functions for Firebase - Express example 2/3 - using middleware
const functions = require("firebase-functions")
const cors = require("cors")
const express = require("express")
/* Express with CORS */
const app2 = express()
app2.use(cors({ origin: true }))
app2.get("*", (request, response) => {
response.send("Hello from Express on Firebase with CORS!")
})
@jthegedus
jthegedus / CF4F-express|functionsES6|index-03.js
Last active March 4, 2019 06:32
Cloud Functions for Firebase - Express example 3/3 - using CORS and automatically appending a trailing slash
const functions = require("firebase-functions")
const cors = require("cors")
const express = require("express")
/* Express with CORS & automatic trailing '/' solution */
const app3 = express()
app3.use(cors({ origin: true }))
app3.get("*", (request, response) => {
response.send(
"Hello from Express on Firebase with CORS! No trailing '/' required!"
@jthegedus
jthegedus / CFF-next|.gitignore
Last active July 25, 2017 10:15
Cloud Functions for Firebase - NextJS example
# src/app/.gitignore
.next
@jthegedus
jthegedus / CFF-next|norewrite|firebase.json
Last active July 30, 2018 23:50
Cloud Functions for Firebase - NextJS example
{
"hosting": {
"public": "src/public"
},
"functions": {
"source": "src/functions"
}
}
@jthegedus
jthegedus / CFF-next|.firebaserc
Created July 20, 2017 15:05
Cloud Functions for Firebase - NextJS example
{
"projects": {
"default": "this will be the name you gave to the firebase project you linked"
}
}
@jthegedus
jthegedus / CFF-next|functions|.gitignore
Last active July 25, 2017 05:05
Cloud Functions for Firebase - NextJS example
# src/functions/.gitignore
next
@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|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|firebase.json
Created July 25, 2017 08:42
Cloud Functions for Firebase - NextJS example
{
"hosting": {
"public": "src/public",
"rewrites": [
{
"source": "**/**",
"function": "next"
}
]
},