Skip to content

Commit 7ca0947

Browse files
authored
Add Storage emulator snippets that were previously hard-coded in docs. (#304)
* Initial push to prepare for review. * Fix lint error. * Generate /snippets/storage-next/emulator-suite. * Fix errant RTDB reference in comment lines.
1 parent 36740fb commit 7ca0947

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This snippet file was generated by processing the source file:
2+
// ./storage-next/emulator-suite.js
3+
//
4+
// To update the snippets in this file, edit the source and then run
5+
// 'npm run snippets'.
6+
7+
// [START storage_emulator_connect_modular]
8+
import { getStorage, connectStorageEmulator } from "firebase/storage";
9+
10+
const storage = getStorage();
11+
if (location.hostname === "localhost") {
12+
// Point to the Storage emulator running on localhost.
13+
connectStorageEmulator(storage, "localhost", 9199);
14+
}
15+
// [END storage_emulator_connect_modular]

storage-next/emulator-suite.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// [SNIPPET_REGISTRY disabled]
2+
// [SNIPPETS_SEPARATION enabled]
3+
4+
function onDocumentReady() {
5+
// [START storage_emulator_connect]
6+
const { getStorage, connectStorageEmulator } = require("firebase/storage");
7+
8+
const storage = getStorage();
9+
if (location.hostname === "localhost") {
10+
// Point to the Storage emulator running on localhost.
11+
connectStorageEmulator(storage, "localhost", 9199);
12+
}
13+
// [END storage_emulator_connect]
14+
}

storage/emulator-suite.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// These samples are intended for Web so this import would normally be
2+
// done in HTML however using modules here is more convenient for
3+
// ensuring sample correctness offline.
4+
import firebase from "firebase/app";
5+
import "firebase/storage";
6+
7+
function onDocumentReady() {
8+
// [START storage_emulator_connect]
9+
var storage = firebase.storage();
10+
if (location.hostname === "localhost") {
11+
// Point to the Storage emulator running on localhost.
12+
storage.useEmulator("localhost", 9199);
13+
}
14+
// [END storage_emulator_connect]
15+
}
16+

0 commit comments

Comments
 (0)