Closed se1exin closed 5 years ago
Remove MB_DISABLE_CORS=true
. CORS support is enabled by default, so it should work out of the box.
Please try again without that env variable and report any problem, Thanks!
As mention in my original post I had also tried that:
with and without the MB_DISABLE_CORS flag
--
Removing MB_DISABLE_CORS=true
continues to have CORS errors:
docker run -p 8080:8080 -e MB_KEY=$MB_KEY machinebox/classificationbox
Access to XMLHttpRequest at 'http://localhost:8080/classificationbox/models/mymodel/predict' from origin 'http://192.168.10.10' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Note that when the MB_DISABLE_CORS
is removed there is no 404
error. Adding MB_DISABLE_CORS
to the box throws the additional 404
error as mentioned in my original post above.
Hey @se1exin - When you run the container, does it give you a git hash in the console?
e.g. mine says
services $ docker run -p 8080:8080 -e "MB_KEY=$MB_KEY" machinebox/classificationbox
[INFO] starting...
Welcome to Classificationbox by Machine Box
(classificationbox 9d3d9db)
Visit the console to see what this box can do:
http://localhost:8080
If you have any questions or feedback, get in touch:
https://machinebox.io/contact
Please consider buying a subscription:
https://machinebox.io/#pricing
Report bugs and issues:
https://github.com/machinebox/issues
Tell us what you build on Twitter @machineboxio
Do docker ps
and make sure no other instances are running. Docker lets you (seemingly) bind multiple things to the same port, so it's possible another version with CORS disabled is running and intercepting the request.
docker ps
// will show list of running contains
docker stop CONTAINERID << will stop the container
@matryer the git hash of the container is:
Welcome to Classificationbox by Machine Box
(classificationbox 9d3d9db)
And docker ps
only lists one container:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bd160cc6a24e machinebox/classificationbox "/app/classification…" 2 hours ago Up 2 hours 0.0.0.0:8080->8080/tcp modest_euclid
I've been able to work around the issue by proxying requests via the node package local-cors-proxy
, and if/when I use the container in production the requests would be proxied via the server side application as well, so realistically CORS is not an issue. I was just a bit stumped when hacking locally and I couldn't get AJAX calls working.
I'd also like to restart my computer just to double check it wasn't something cached or what-have-you, but I'm now mid-training with a dataset of about 18 million inputs - so I won't be able to do a reboot for at least another 20 or so hours 😂
--
PS. Re-reading my earlier reply, sorry if it came off a bit rude, it was not intended - I had just woken up.
PPS. I came across Machinebox from your episode on the Changelog podcast. Was a good listen and the boxes are very cool and super easy to train and use! Keep up the awesome work 🤘
Closing as using a local proxy works fine for me
So I've been playing with Classificationbox, it's very cool and works very well when interacting with it directly, however I'm unable to call the predictions endpoint via Javascript, specifically JQuery, with and without the
MB_DISABLE_CORS
flag.Browser: Google Chrome Version
72.0.3626.121
ClassificationboxV ersion: Not sure as Docker tag is alwayslatest
, but the image was pulled on 9/3/19 (the date of this post).Steps to reproduce:
docker run -p 8080:8080 -e MB_KEY=$MB_KEY -e MB_DISABLE_CORS='true' machinebox/classificationbox
_Note: Have also tried the command with
MB_DISABLE_CORS=true
(without quotes)._Create Model and import data into Model using REST API, then..
JQuery call:
Chrome fails pre-flight with error:
OPTIONS http://localhost:8080/classificationbox/models/mymodel/predict net::ERR_ABORTED 404 (Not Found)
--
Testing with Postman with the exact same URL and JSON data yields successful results.
Additionally, GET requests via
$.ajax
also fail with the same 404 error - e.g.GET http://localhost:8080/classificationbox/models/mymodel/stats