Friday, 5 May 2017

Trying to avoid a cross-origin request error by setting up a local server with Node's http-server module

I'd like to upload file to Firebase's Google Cloud Storage using Javascript. The problem is that I'm testing this on a local server, using npm run dev, and apparently this isn't allowing me to upload files to FB storage locations (that look like gs://xyz.appspot.com) because of cross-origin request blocking.

So, according to this recommendation, I'm now trying to set up an http server using Node's http-server module. My project is generated by Webpack and the output file is located in dist. Within dist I run http-server index.html and I see:

Starting up http-server, serving index.html
Available on:
  http://127.0.0.1:8080
  http://192.XXX:8080
Hit CTRL-C to stop the server
[Fri May 05 2017 08:23:37 GMT+0200 (CEST)] "GET /__webpack_hmr" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) xAppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
[Fri May 05 2017 08:23:37 GMT+0200 (CEST)] "GET /__webpack_hmr" Error (404): "Not found"

And these last two messages keep repeating.

I go to the localhost address and there is no page found (404 error). Any ideas what is going wrong with my node server?

EDIT:

Actually, http-server takes the path of the file to be served, so I should have been using:

http-server ./

This still doesn't solve my problem. The page loads, but I get the same cross-origin error.



via David J.

No comments:

Post a Comment