GithubHelp home page GithubHelp logo

CORS about unofficial-jisho-api HOT 13 CLOSED

mistval avatar mistval commented on August 30, 2024
CORS

from unofficial-jisho-api.

Comments (13)

jeffbernst avatar jeffbernst commented on August 30, 2024 1

Just tried it out and it works great. Thanks again! 😀

from unofficial-jisho-api.

mistval avatar mistval commented on August 30, 2024

Hi, thanks for the issue. I'll see about adding an argument so that you can specify request parameters such as proxy.

In the meantime, looking at request's documentation it sounds like you can set an HTTP_PROXY environment variable and it should use that. Not the greatest solution but should work in a pinch.

from unofficial-jisho-api.

jeffbernst avatar jeffbernst commented on August 30, 2024

Ah ok cool, thanks!

from unofficial-jisho-api.

mistval avatar mistval commented on August 30, 2024

I added a way to configure request options in the newly available version 1.1.2.

Check out the updated README for examples of how to configure a proxy.

Feel free to reopen the issue if there's any problem :)

from unofficial-jisho-api.

jeffbernst avatar jeffbernst commented on August 30, 2024

That was so fast -- thank you!

I'm trying it out now and getting an error (see image).
cleanshot 2018-10-22 at 22 51 01

This is the configuration I used:

const jishoApi = require('unofficial-jisho-api');
const jisho = new jishoApi({ proxy: 'https://cors-anywhere.herokuapp.com/' });

jisho.searchForPhrase('日').then(result => {
  console.log(result);
});

If I use that proxy and make a fetch request directly to the Jisho API it works fine with something like this:

const proxy = 'https://cors-anywhere.herokuapp.com/'
const word = '余計';
const url = proxy + 'http://jisho.org/api/v1/search/words?keyword=' + word;

const response = await fetch(url);
const json = await response.json();
console.log(json)

from unofficial-jisho-api.

mistval avatar mistval commented on August 30, 2024

Ah that proxy is a little bit weird, I don't think you can make it work by specifying options to the request module. How about this then, I'll expose the parsing functions and then you can get the HTML body of the page however works for you, pass it into the parsing functions, and get JSON out.

from unofficial-jisho-api.

mistval avatar mistval commented on August 30, 2024

So for phrase search (official API) you would do

  const proxy = 'https://cors-anywhere.herokuapp.com/'
  const word = '余計';
  const url = proxy + jisho.getUriForPhraseSearch(word);

  const response = await fetch(url);
  const json = await response.json();
  console.log(json);

And for kanji search:

  const proxy = 'https://cors-anywhere.herokuapp.com/'
  const kanji = '余';
  const url = proxy + jisho.getUriForKanjiSearch(kanji);

  const response = await fetch(url);
  const json = jisho.parseKanjiPageHtml(await response.body()); // Or however you access the body of the response using whatever library you're using for HTTP requests
  console.log(json);

Would that work?

from unofficial-jisho-api.

jeffbernst avatar jeffbernst commented on August 30, 2024

Yeah for sure! That works for me. And one of the main things I'd want to get would be the sentences.

Let me know if I can help with any of this too! I appreciate everything you've already put together. Also, there's a chance I'll end up creating my own database with the dictionary/sentence files eventually so I don't want to feel like I've requested stuff from you that I didn't use enough.

from unofficial-jisho-api.

mistval avatar mistval commented on August 30, 2024

Please try out the new v1.1.3 and let me know if it gets the job done :) Examples for fetching the pages yourself and having the module parse them are near the bottom of the updated README

For the sentences, the furigana has mistakes 5-10% of the time. At some point I'd like to see about improving that. If you notice sentences where the API returns different furigana compared to the Jisho.org website, feel free to comment on the issue I have open for that and include the search term and the incorrect sentence.

By the way, if you don't need the furigana, you might consider downloading Tatoeba, that's where (all of?) Jisho's example sentences come from and you can download their entire database as a big TSV file.

from unofficial-jisho-api.

jeffbernst avatar jeffbernst commented on August 30, 2024

Hey sorry for the late response -- had a busy week! I'm about to run back out but should be able to try out the new features within the next couple of days. Thanks again for adding this stuff! :)

And I appreciate the link to Tatoeba! I've been thinking about just downloading the files like you said and setting up my own server.

from unofficial-jisho-api.

gfreecs0510 avatar gfreecs0510 commented on August 30, 2024

hi @mistval ohayo gozaimasu, is there really no other way than to make a proxy server to resolve the CORS issue? thank you in advance

from unofficial-jisho-api.

mistval avatar mistval commented on August 30, 2024

Hi @gfreecs0510 If you want to use this package (or the Jisho API in general) in a website, you'll have to use a proxy (or maybe try asking nicely on Jisho's forum for them to allow CORS).

from unofficial-jisho-api.

gfreecs0510 avatar gfreecs0510 commented on August 30, 2024

@mistval thank you very much, cheers :)

from unofficial-jisho-api.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.