Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong input handling in server/app.ts #145

Open
YggdrasiI opened this issue Nov 18, 2019 · 2 comments
Open

Wrong input handling in server/app.ts #145

YggdrasiI opened this issue Nov 18, 2019 · 2 comments

Comments

@YggdrasiI
Copy link

Hello Bagbag,

I've think that an app interface can not be used because JSON.parse is called twice.
From server/app.ts:

app.post('/api/query', (req, res) => {
    res.header('Access-Control-Allow-Origin', '*');

    let query;
    try {
      **query = JSON.parse(req.body);**
    } catch (e) {
      res.status(400).json({
        result: null,
        err: [e.message]
      });
      return;
    }
[…]
}

Here, req.body seems to be already decoded. I've get

curl -d '{}' "https://mediathekviewweb.de/api/query"
{"result":null,"err":["Unexpected token o in JSON at position 1"]}

Regards YggdrasiI

@bagbag
Copy link
Member

bagbag commented Nov 18, 2019

I guess you're right. As a workaround for now you can set the Content-Type header to text/plain.

curl -d '{}' -H "Content-Type: text/plain" "https://mediathekviewweb.de/api/query"

@YggdrasiI
Copy link
Author

Thanks, I've tested the workaround and got search results. (Meanwhile I (re-)detect how to use the socketIO-approach, but getting information with a simple request is still more likeable. :))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants