dijs / wiki

Wikipedia Interface for Node.js
MIT License
315 stars 61 forks source link

Origin 'null' in request #39

Closed arliber closed 7 years ago

arliber commented 7 years ago

Hi,

I'm trying to use WikiJs directly from the client within webpack environment. Unfortunately, I get the following error:

Fetch API cannot load https://en.wikipedia.org/w/api.php?prop=info%7Cpageprops&inprop=url&ppprop=disambiguation&titles=Batman&format=json&action=query&redirects=. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

which leads to:

Uncaught (in promise) TypeError: Failed to fetch

what am I missing?

Thanks in advance

dijs commented 7 years ago

This is a known issue. It's a CORS issue.

You could circumvent this by running wikijs from within a WebWorker, which would be preferred anyway since it will not block the UI thread.

But the real solution of using the JSONP WikiMedia API has not been implemented yet.

Mechasparrow commented 7 years ago

Actually, I discovered a new way to circumvent this issue. I'll run some tests and then maybe give a pull request. You can set cors=*

dijs commented 7 years ago

Sounds good. Can't wait to check it out.

Mechasparrow commented 7 years ago

@dijs Should be solved with https://github.com/dijs/wiki/pull/40 pull request.

arliber commented 7 years ago

Works perfectly! While not directly related - I tried using wiki under Node 6.9 and since there are no native import I used require instead - and nothing worked (e.g. when executing wiki.page, page was undefined) Does it strictly require next node version? Thanks

Mechasparrow commented 7 years ago

Could you show us some example source code. I might know a solution.

On Apr 8, 2017 11:20, "Arik Liber" notifications@github.com wrote:

Works perfectly! While not directly related - I tried using wiki under Node 6.9 and since there are no native impoert I used require instead - and nothing worked (e.g. when executing wiki.page, page was undefined) Does it strictly require next node version? Thanks

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/dijs/wiki/issues/39#issuecomment-292728269, or mute the thread https://github.com/notifications/unsubscribe-auth/AIhrIJfzXdVhMSr5Oz5RBjCNipLKlfG1ks5rt7PZgaJpZM4MpG5R .

Mechasparrow commented 7 years ago

@LeonLiber I'd highly recommend you open a separate issue, so this can be handled better.