Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔥base #1

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from
5 changes: 5 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "containment-game-js"
}
}
23 changes: 23 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"hosting": {
"public": "dist",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
},
"storage": {
"rules": "storage.rules"
}
}
4 changes: 4 additions & 0 deletions firestore.indexes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"indexes": [],
"fieldOverrides": []
}
17 changes: 17 additions & 0 deletions firestore.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {

// This rule allows anyone on the internet to view, edit, and delete
// all data in your Firestore database. It is useful for getting
// started, but it is configured to expire after 30 days because it
// leaves your app open to attackers. At that time, all client
// requests to your Firestore database will be denied.
//
// Make sure to write security rules for your app before that time, or else
// your app will lose access to your Firestore database
match /{document=**} {
allow read, write: if request.time < timestamp.date(2020, 5, 15);
}
}
}
1 change: 1 addition & 0 deletions functions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
30 changes: 30 additions & 0 deletions functions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const admin = require('firebase-admin');
const functions = require('firebase-functions');
admin.initializeApp();
const db = admin.firestore();

const TOPIC_TEST = 'logs-test'

exports.logSubTest = functions.region('europe-west3').pubsub.topic(TOPIC_TEST).onPublish(async (message) => {
try {
name = message.json.name;
const {
type,
payload,
version,
timestamp,
} = message.json
if (type && payload && version && timestamp) {
db.collection('log/' + type).add({
versionLog: version,
timestamp,
...payload
})
} else {
console.error('invalid format', message.json)
}
} catch (e) {
console.error('PubSub message was not JSON', e, message);
}

});
22 changes: 22 additions & 0 deletions functions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "8"
},
"dependencies": {
"firebase-admin": "^8.9.0",
"firebase-functions": "^3.3.0"
},
"devDependencies": {
"firebase-functions-test": "^0.1.6"
},
"private": true
}
Loading