Skip to content

Commit e8a3920

Browse files
authored
Remove database field from REST API request body. (#2188)
* Remove database field from REST API request body. * [AUTOMATED]: Prettier Code Styling * Fix type and add comments about the emulator. * [AUTOMATED]: Prettier Code Styling
1 parent c9dbf19 commit e8a3920

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/firestore/src/platform_browser/webchannel_connection.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { StreamBridge } from '../remote/stream_bridge';
3838
import { assert, fail } from '../util/assert';
3939
import { Code, FirestoreError } from '../util/error';
4040
import * as log from '../util/log';
41+
import { Indexable } from '../util/misc';
4142
import { Rejecter, Resolver } from '../util/promise';
4243
import { StringMap } from '../util/types';
4344

@@ -172,7 +173,13 @@ export class WebChannelConnection implements Connection {
172173
}
173174
});
174175

175-
const requestString = JSON.stringify(request);
176+
// The database field is already encoded in URL. Specifying it again in
177+
// the body is not necessary in production, and will cause duplicate field
178+
// errors in the Firestore Emulator. Let's remove it.
179+
const jsonObj = ({ ...request } as unknown) as Indexable;
180+
delete jsonObj.database;
181+
182+
const requestString = JSON.stringify(jsonObj);
176183
log.debug(LOG_TAG, 'XHR sending: ', url + ' ' + requestString);
177184
// Content-Type: text/plain will avoid preflight requests which might
178185
// mess with CORS and redirects by proxies. If we add custom headers

0 commit comments

Comments
 (0)