Skip to content

Commit e3c6a27

Browse files
authored
Merge pull request firebase#15 from firebase/marndt-emulators
Emulator snippets for Web SDK to pull into Firesite
2 parents 8a72018 + 1548e6c commit e3c6a27

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

database/emulator-suite.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
function onDocumentReady() {
3+
4+
//[START rtdb_emulator_connect]
5+
if (location.hostname === "localhost") {
6+
7+
var firebaseConfig = {
8+
// Point to the RTDB emulator running on localhost.
9+
// In almost all cases the ns (namespace) is your project ID.
10+
databaseURL: "http://localhost:9000?ns=YOUR_DATABASE_NAMESPACE"
11+
}
12+
13+
var myApp = firebase.initializeApp(firebaseConfig);
14+
var db = myApp.database();
15+
}
16+
// [END rtdb_emulator_connect]
17+
}
18+
19+
function flushRealtimeDatabase(firebase) {
20+
21+
//[START rtdb_emulator_flush]
22+
// With a database Reference, write null to clear the database.
23+
firebase.database().ref().set(null);
24+
// [END rtdb_emulator_connect]
25+
}

firestore/emulator-suite.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
export async function onDocumentReady(firebaseApp) {
3+
4+
//[START fs_emulator_connect]
5+
// firebaseApp previously initialized using firebase.initializeApp().
6+
var db = firebaseApp.firestore();
7+
if (location.hostname === "localhost") {
8+
// Note that the Firebase Web SDK must connect to the WebChannel port
9+
db.settings({
10+
host: "localhost:8081",
11+
ssl: false
12+
});
13+
}
14+
// [END fs_emulator_connect]
15+
}

0 commit comments

Comments
 (0)