Skip to content

Instantly share code, notes, and snippets.

@jthegedus
jthegedus / express-functions.js
Last active April 20, 2020 04:04
Express & Cloud Functions for Firebase example
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
// Express Servers
const {simpleServer, corsServer, cleanPathServer} = require('./server');
// HTTP Cloud Functions
const simple = functions.https.onRequest(simpleServer);
@jthegedus
jthegedus / function.js
Created May 26, 2019 06:50
Cloud Run web server and dependencies example
exports.helloWorld = (req, res) => {
res.send('Hello, World');
};
@jthegedus
jthegedus / Dockerfile
Created May 14, 2019 23:25
Berglas w Node.js
FROM node:10-alpine
RUN apk add ca-certificates
ENV NODE_ENV=production
WORKDIR /urs/src/app
COPY package.json yarn.lock ./
RUN yarn install --production
@jthegedus
jthegedus / firebase-cron-cloud-functions.js
Last active May 8, 2019 13:04
jthegedus|firebase-cron-cloud-functions
const functions = require('firebase-functions');
exports.englishSyntax = functions.pubsub
.schedule('every 10 minutes')
.timeZone('Australia/NSW')
.onRun(context => {
console.log('triggered every 10 minutes', context);
});
exports.cronSyntax = functions.pubsub
import { onNewUser } from "./onNewUser/function";
// functions in this object will be prefixed with "users"
// Eg: auth-onNewUser
const auth = { onNewUser };
export { auth };
@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!"
+- dist/ # compiled code
| |
| +- index.js # CF entrypoint, defined by pkg.json "main" field
| +- index.js.map # maps compiled to raw source in ../src/
+- node_modules/ # ignored by firebase-tools on upload
+- src/ # raw source code to compile
| |
| +- index.<ext> # entrypoint to compile
+- <config file> # config file depending on the tool
+- .firebaserc # firebase project identification config
@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 / StayFocusd Settings
Last active October 16, 2018 02:04
StayFocusd web browser extension settings
## Active Days:
all except Saturday
## Active Hours:
12am-10pm
## Blocked Sites:
bbc.co.uk
cnn.com
collegehumor.com
@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"
}
}