viruschidai / validate-vat-ts

A library for validating VAT number
32 stars 13 forks source link

Doesn't work from client #4

Closed sodik82 closed 4 years ago

sodik82 commented 4 years ago

I am getting

Access to fetch at 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService' from origin 'http://localhost:6006' 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. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

I tried also no-cors but it is not useful as you can't read response.

https://stackoverflow.com/questions/54896998/how-to-process-fetch-response-from-an-opaque-type

Not sure what to do with it.

viruschidai commented 4 years ago

Was overstated in the readme, seems cannot directly call the VIEW soap service from browser. If you really want to call the service from browser, probably have a proxy route in your API server.

benbucksch commented 4 years ago

Yes, this is a server-side component. You cannot contact the EU government server directly from the browser.

zedrdave commented 4 years ago

OK thanks, I guess I'll write my own code or use another package.

benbucksch commented 4 years ago

It's not a question of code. Browsers do not allow your website to contact arbitrary servers on the Internet. At least not using the protocol that the EU gov server uses. You need some sort of server in your domain in any case.

thebillg commented 4 years ago

I think the EU gov server does not like directly access from browser due to CORS settings. Unless there is a service in the middle available that allows directly access from browser with CORS setting like Access-Control-Allow-Origin: *, you have to call it from server side.