Skip to content
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

STORAGE_EMULATOR_HOST getting TypeError: Only HTTP(S) protocols are supported #2158

Closed
Ridermansb opened this issue Mar 5, 2023 · 5 comments
Assignees
Labels
api: storage Issues related to the googleapis/nodejs-storage API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue.

Comments

@Ridermansb
Copy link

I have my firebase local emulator running with storage on port 9199

image

I set the STORAGE_EMULATOR_HOST=localhost:9199

I initialize my cloud storage as this..

import { Storage } from "@google-cloud/storage";
const storage = new Storage();

log('Storage running with config "%o"', {
  projectId: storage.projectId, // '{{projectId}}'
  apiEndpoint: storage.apiEndpoint, // 'https://localhost:9199'
  baseUrl: storage.baseUrl // 'localhost:9199'
});

When I tried to upload the file to my local storage emulator using this code..

  const bucket = storage.bucket("gs://{{MY_PROJECT_ID}}.appspot.com");
  const file = bucket.file(`user-url-assets/${userUrl.id}}/${fileName}`);
  return file.save(buffer, {
    public: true,
    metadata: {
      cacheControl: "public, max-age=31536000",
      metadata: {
        ...userUrl
      }
    }
  });

I'm getting this error:

/Users/ridermansb/Projects/mine/pageHistory/web/node_modules/node-fetch/lib/index.js:1331
throw new TypeError('Only HTTP(S) protocols are supported');
^
TypeError: Only HTTP(S) protocols are supported
at getNodeRequestOptions (/Users/ridermansb/Projects/mine/pageHistory/web/node_modules/node-fetch/lib/index.js:1331:9)
at /Users/ridermansb/Projects/mine/pageHistory/web/node_modules/node-fetch/lib/index.js:1454:19
at new Promise ()
at fetch (/Users/ridermansb/Projects/mine/pageHistory/web/node_modules/node-fetch/lib/index.js:1451:9)
at teenyRequest (/Users/ridermansb/Projects/mine/pageHistory/web/node_modules/teeny-request/build/src/index.js:203:30)
at Object.request (/Users/ridermansb/Projects/mine/pageHistory/web/node_modules/teeny-request/build/src/index.js:243:9)
at Timeout.makeRequest [as _onTimeout] (/Users/ridermansb/Projects/mine/pageHistory/web/node_modules/retry-request/index.js:171:28)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7)

Some environment variables are set

  FIRESTORE_EMULATOR_HOST: 'localhost:8080',
  FIREBASE_AUTH_EMULATOR_HOST: 'localhost:9099',
  FIREBASE_PUBSUB_EMULATOR_HOST: 'localhost:8085',
  FIREBASE_STORAGE_EMULATOR_HOST: 'localhost:9199',
  STORAGE_EMULATOR_HOST: 'localhost:9199',
  GCLOUD_PROJECT: '{{PROJECT_ID}}'
@Ridermansb Ridermansb added priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue. labels Mar 5, 2023
@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/nodejs-storage API. label Mar 5, 2023
@ddelgrosso1
Copy link
Contributor

Hi @Ridermansb the recommendation currently is to use apiEndpoint. STORAGE_EMULATOR_HOST is noted as experimental. There are some other issues being worked on around compatibility with the Firebase Emulator #2092.

@ddelgrosso1 ddelgrosso1 self-assigned this Mar 6, 2023
@Ridermansb
Copy link
Author

Hey @ddelgrosso1 .. I tried as well.. get the same results :(

@ddelgrosso1
Copy link
Contributor

@Ridermansb I setup and ran some tests against the Firebase emulator today. Unfortunately I did not get any errors. The code I used is below:

const s = new Storage({projectId: 'MY-PROJECT', apiEndpoint: 'http://127.0.0.1:9199'});
const b = s.bucket("gs://MY-PROJECT.appspot.com")
const f = b.file('MY-FILE');

async function testLargeResumable() {
  try {
    await f.save("hell world", {
      public: true,
      metadata: {
        cacheControl: "public, max-age=31536000",
        metadata: {
          someThing: 'http://blah.com'
        }
  }});

Is there any other information that might be helpful in debugging / reproducing this?

@ddelgrosso1
Copy link
Contributor

Going to close this as I am unable to reproduce locally. If more information on recreating this becomes available please feel free to reopen with the additional info.

@jelling
Copy link

jelling commented Nov 7, 2023

At least in my case, root cause appears to be that the storage library is passing the IP address into the protocol property when it calls node-fetch:

Screen Shot 2023-11-07 at 11 23 48 AM

Like OP, this happens even when using the apiEndpoint property:

  const s = new Storage({
    projectId: "reboot-tv-test",
    // neither http or https work
    // apiEndpoint: "http://127.0.0.1:9199",
    apiEndpoint: "https://127.0.0.1:9199",
  });
  const b = s.bucket("gs://reboot-tv-test.appspot.com");
  const file = b.file(storagePath);
  const tmpFilePath = `${os.tmpdir()}/${storagePath}`;
  await file.download({ destination: tmpFilePath, validation: false });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/nodejs-storage API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants