-
Notifications
You must be signed in to change notification settings - Fork 948
Add useEmulator() to Storage #4346
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
Changes from all commits
71fee5e
190f850
177334b
0f11e2b
de51f3d
fc5af01
c810327
2ee0f18
57d1a86
f499be2
b6e0ffd
ae1c345
f2dbc7c
ed256f5
ed28cf6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'firebase': minor | ||
'@firebase/storage': minor | ||
'@firebase/storage-types': minor | ||
--- | ||
|
||
Add `storage().useEmulator()` method to enable emulator mode for storage, allowing users | ||
to set a storage emulator host and port. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,4 +63,4 @@ | |
"url": "https://github.com/firebase/firebase-js-sdk/issues" | ||
}, | ||
"typings": "dist/index.d.ts" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,11 +18,16 @@ | |
/** | ||
* @fileoverview Functions to create and manipulate URLs for the server API. | ||
*/ | ||
import { DEFAULT_HOST } from './constants'; | ||
import { UrlParams } from './requestinfo'; | ||
|
||
export function makeUrl(urlPart: string): string { | ||
return `https://${DEFAULT_HOST}/v0${urlPart}`; | ||
export function makeUrl(urlPart: string, host: string): string { | ||
const protocolMatch = host.match(/^(\w+):\/\/.+/); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this because emulator uses http when production use defaults to https. Seems cleaner to let the host string contain a protocol or not, and if so, parse it in this one function, than to store protocol as a separate property on StorageService and get it everywhere service.host is also used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit/optional, I think using replace with callback would save some lines and be more readable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't figure out how to easily set up a regex that would call the callback if the protocol wasn't there so I left it alone for now. We can always optimize any time so let me know if you have a snippet you want to put in. |
||
const protocol = protocolMatch?.[1]; | ||
let origin = host; | ||
if (protocol == null) { | ||
origin = `https://${host}`; | ||
} | ||
return `${origin}/v0${urlPart}`; | ||
} | ||
|
||
export function makeQueryString(params: UrlParams): string { | ||
|
Uh oh!
There was an error while loading. Please reload this page.