Skip to content

Instantly share code, notes, and snippets.

View yonahforst's full-sized avatar

Yonah Forst yonahforst

View GitHub Profile
@yonahforst
yonahforst / serverless.yml
Last active December 26, 2018 08:47
Getting started with `serverless-cqrs` -  part 3 - serverless.yml
service: myService
## define some static variables
custom:
writeModelTableName: commitsByEntityIdAndVersion
writeModelIndexName: indexByEntityNameAndCommitId
readModelDomainName: readmodel
provider:
name: aws
@yonahforst
yonahforst / events.js
Created November 2, 2018 15:17
todo list events
const events = [
{ type: 'TodoAdded', title: 'Learn CQRS' },
{ type: 'TodoAdded', title: 'Save the world' },
{ type: 'TodoCompleted', index: 0 },
{ type: 'TodoRemoved', index: 1 },
]
@yonahforst
yonahforst / reducer.js
Created November 2, 2018 15:17
todo list reducer
const reducer = (state, event) => {
switch (event.type) {
case 'TodoAdded':
// append event to the list of existing events.
return [
...state,
{ title: event.title, completed: false },
]
case 'TodoRemoved':
@yonahforst
yonahforst / rules.js
Last active February 20, 2018 18:04
database rules
{
"rules": {
"messages": {
"$roomId": {
// users can only chat in their own private room. admins can chat anywhere.
".read": "$roomId === auth.uid || auth.token.admin === true",
"$messageId": {
// can only write new data, not modify old
".write": "($roomId === auth.uid || auth.token.admin === true) && !data.exists() && newData.exists()",
// must contain only userId and body
@yonahforst
yonahforst / index.js
Last active February 15, 2018 23:55
index.js
const functions = require('firebase-functions')
const admin = require('firebase-admin')
const fetch = require('node-fetch')
admin.initializeApp(functions.config().firebase)
// create an authentication endpoint.
// calls our backend to validate JWT
// if it passes, generate firebase token for the user
module.exports.authenticate = functions.https
.onRequest((req, res) => {