Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2937,7 +2937,11 @@ class File extends ServiceObject<File, FileMetadata> {

let url: string;

if (this.storage.customEndpoint) {
const EMULATOR_HOST = process.env.STORAGE_EMULATOR_HOST;

if (this.storage.customEndpoint && typeof EMULATOR_HOST === 'string') {
url = `${this.storage.apiEndpoint}/${this.bucket.name}`;
} else if (this.storage.customEndpoint) {
url = this.storage.apiEndpoint;
} else if (options.virtualHostedStyle) {
url = `https://${this.bucket.name}.storage.${universe}/`;
Expand Down
28 changes: 28 additions & 0 deletions test/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3578,6 +3578,34 @@ describe('File', () => {
);
});

it('should append bucket name to the URL when using the emulator', done => {
const emulatorHost = 'http://127.0.0.1:9199';
const originalApiEndpoint = STORAGE.apiEndpoint;
const originalCustomEndpoint = STORAGE.customEndpoint;
const originalEnvHost = process.env.STORAGE_EMULATOR_HOST;

process.env.STORAGE_EMULATOR_HOST = emulatorHost;
STORAGE.apiEndpoint = emulatorHost;
STORAGE.customEndpoint = true;

file.generateSignedPostPolicyV4(
CONFIG,
(err: Error, res: SignedPostPolicyV4Output) => {
STORAGE.apiEndpoint = originalApiEndpoint;
STORAGE.customEndpoint = originalCustomEndpoint;
if (originalEnvHost) {
process.env.STORAGE_EMULATOR_HOST = originalEnvHost;
} else {
delete process.env.STORAGE_EMULATOR_HOST;
}

assert.ifError(err);
assert.strictEqual(res.url, `${emulatorHost}/${BUCKET.name}`);
done();
}
);
});

describe('expires', () => {
it('should accept Date objects', done => {
const expires = new Date(Date.now() + 1000 * 60);
Expand Down
Loading