Skip to content

Commit

Permalink
removed need to set firebase.server
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Krenn authored and Marc Krenn committed Sep 21, 2016
1 parent 7818157 commit ad54474
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 29 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ This module is based on [Firebase's REST API](https://firebase.google.com/docs/r
| Table of contents |
| :--- |
| [**1) Properties**](https://github.com/marckrenn/framer-Firebase#1-properties) |
| \|--- [firebase**.projectID**, **.secret**, **.server**](https://github.com/marckrenn/framer-Firebase#-firebaseprojectid-firebasesecret-firebaseserver) |
| \|--- [firebase**.projectID**, **.secret**](https://github.com/marckrenn/framer-Firebase#-firebaseprojectid-firebasesecret) |
| \|--- [firebase**.debug**](https://github.com/marckrenn/framer-Firebase#-firebasedebug) |
| \|--- [firebase**.status**](https://github.com/marckrenn/framer-Firebase#-firebasestatus-read-only) |
| [**2) Methods**](https://github.com/marckrenn/framer-Firebase#2-methods) |
Expand All @@ -92,7 +92,7 @@ This module is based on [Firebase's REST API](https://firebase.google.com/docs/r

### 1) Properties

#### • firebase.projectID, firebase.secret, firebase.server
#### • firebase.projectID, firebase.secret
---
The properties **projectID**, **secret** and **server** are required for the module to function properly.

Expand All @@ -102,13 +102,12 @@ The required information is located at https://firebase.google.com → *Console*
firebase = new Firebase
projectID: ___________ # 1) ... Database → first part of URL
secret: ______________ # 2) ... Project Settings → Database → Database Secrets
server: ______________ # 3) Get this info by setting `server: undefined´ first
```


| 1) projectID | 2) secret | 3) server |
| :---: | :---: | :---: |
| ![gif for ants I](http://i.giphy.com/xT4uQFz8q6HAHKkfi8.gif) | ![gif for ants II](http://i.giphy.com/l3E6oeWMBJMc9Sk7u.gif) | ![gif for ants III](http://i.giphy.com/l3E6EnKJt8bySmMkU.gif) |
| 1) projectID | 2) secret |
| :---: | :---: |
| ![gif for ants I](http://i.giphy.com/xT4uQFz8q6HAHKkfi8.gif) | ![gif for ants II](http://i.giphy.com/l3E6oeWMBJMc9Sk7u.gif) |

> **Protip:** Contrary to what I did in the gif, I advise you **NOT** to share your Firebase *secret* publicly, as it allow others to alter the data stored in your database. If you do so by accident, you can always revoke access by deleting the shared *secret* and creating a new one at https://firebase.google.com*Console**Project Settings**Database**Database Secrets*.
Expand Down
29 changes: 6 additions & 23 deletions firebase.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@



# 'Firebase REST API Class' module v1.0
# by Marc Krenn, June 22nd, 2016 | [email protected] | @marc_krenn
# 'Firebase REST API Class' module v1.1
# by Marc Krenn, September 21st, 2016 | [email protected] | @marc_krenn

# Documentation of this Module: https://github.com/marckrenn/framer-Firebase
# ------ : ------- Firebase REST API: https://firebase.google.com/docs/reference/rest/database/
Expand All @@ -18,35 +18,18 @@
class exports.Firebase extends Framer.BaseClass



getCORSurl = (server, path, secret, project) ->

switch Utils.isWebKit()
when true then url = "https://#{server}#{path}.json?auth=#{secret}&ns=#{project}&sse=true" # Webkit XSS workaround
else url = "https://#{project}.firebaseio.com#{path}.json?auth=#{secret}"

return url


@.define "status",
get: -> @_status # readOnly

constructor: (@options={}) ->
@projectID = @options.projectID ?= null
@secret = @options.secret ?= null
@server = @options.server ?= undefined # required for WebKit XSS workaround
@debug = @options.debug ?= false
@_status ?= "disconnected"
super


if @server is undefined
Utils.domLoadJSON "https://#{@projectID}.firebaseio.com/.settings/owner.json", (a,server) ->
print msg = "Add ______ server:" + ' "' + server + '"' + " _____ to your instance of Firebase."
console.log "Firebase: #{msg}" if @debug


console.log "Firebase: Connecting to Firebase Project '#{@projectID}' ... \n URL: '#{getCORSurl(@server, "/", @secret, @projectID)}'" if @debug
console.log "Firebase: Connecting to Firebase Project '#{@projectID}' ... \n URL: 'https://#{@projectID}.firebaseio.com'" if @debug
@.onChange "connection"


Expand Down Expand Up @@ -117,7 +100,7 @@ class exports.Firebase extends Framer.BaseClass

if path is "connection"

url = getCORSurl(@server, "/", @secret, @projectID)
url = "https://#{@projectID}.firebaseio.com/.json?auth=#{@secret}"
currentStatus = "disconnected"
source = new EventSource(url)

Expand All @@ -138,7 +121,7 @@ class exports.Firebase extends Framer.BaseClass

else

url = getCORSurl(@server, path, @secret, @projectID)
url = "https://#{@projectID}.firebaseio.com#{path}.json?auth=#{@secret}"
source = new EventSource(url)
console.log "Firebase: Listening to changes made to '#{path}' \n URL: '#{url}'" if @debug

Expand All @@ -148,4 +131,4 @@ class exports.Firebase extends Framer.BaseClass

source.addEventListener "patch", (ev) =>
callback(JSON.parse(ev.data).data, "patch", JSON.parse(ev.data).path, _.tail(JSON.parse(ev.data).path.split("/"),1)) if callback?
console.log "Firebase: Received changes made to '#{path}' via 'PATCH': #{JSON.parse(ev.data).data} \n URL: '#{url}'" if @debug
console.log "Firebase: Received changes made to '#{path}' via 'PATCH': #{JSON.parse(ev.data).data} \n URL: '#{url}'" if @debug

0 comments on commit ad54474

Please sign in to comment.