mutebg / online-store

18 stars 3 forks source link

TypeError: Cannot read property 'storageBucket' of undefined #12

Open ghost opened 6 years ago

ghost commented 6 years ago

When I try to call the products API, firebase reports the following error in index.js

TypeError: Cannot read property 'storageBucket' of undefined at app.get (/user_code/index.js:17:30) at Layer.handle [as handle_request] (/user_code/node_modules/express/lib/router/layer.js:95:5) at next (/user_code/node_modules/express/lib/router/route.js:137:13) at Route.dispatch (/user_code/node_modules/express/lib/router/route.js:112:3) at Layer.handle [as handle_request] (/user_code/node_modules/express/lib/router/layer.js:95:5) at /user_code/node_modules/express/lib/router/index.js:281:22 at Function.process_params (/user_code/node_modules/express/lib/router/index.js:335:12) at next (/user_code/node_modules/express/lib/router/index.js:275:10) at cors (/user_code/node_modules/cors/lib/index.js:188:7) at /user_code/node_modules/cors/lib/index.js:224:17

Looking at the code in app.get('/products', (req, res) => {} I see the following:

const imageBaseUrl = 'https://storage.googleapis.com/' + functions.config().firebase.storageBucket + '/resized/';

Any ideas why the storageBucket is not set?

mutebg commented 6 years ago

I guess you should go to Storage page in Firebase Console and add a bucket. Also, try to make the storage public https://cloud.google.com/storage/docs/access-control/making-data-public Let me know if this doesn't work I will try to remember what I did, it's been a while since I created this project

ghost commented 6 years ago

Hi, Thanks for coming back so quickly! I am using the default bucket as its free. Should it work with this or should I add a new bucket?

mutebg commented 6 years ago

I also use the default one. According to firebase documentation, this should be automatically populated in runtime https://firebase.google.com/docs/functions/config-env

Maybe you can just test it with replacing the config with the name of your bucket, in my case, the name looks like this onlinestore-2e046.appspot.com

MarshalX commented 3 years ago

I had the same problem due to the difference in firebase-functions versions. Don't forget to lock dependencies like me)