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

Unable to get anything with REST API #588

Open
nynjardin opened this issue Jan 4, 2025 · 12 comments
Open

Unable to get anything with REST API #588

nynjardin opened this issue Jan 4, 2025 · 12 comments

Comments

@nynjardin
Copy link

Describe the bug
I've tried to enable REST API without success, I can see the HTTP server is started in the console, but nothing happen when I try to get something.

To reproduce
1-Modifying config.json to enable HTTP server by adding a port in the [ ]
2-Launch the server and wait to the Ready
3-Try any REST endpoint

Additional context
In my case, I've tried multiple server on different computer. Even http://127.0.0.1:88/y/server don't works, so, it's not a firewall problem.

Thanks :)

@nynjardin nynjardin changed the title Unable to get anytthing with REST API Unable to get anything with REST API Jan 4, 2025
@Repflez
Copy link

Repflez commented Jan 4, 2025

Did you add the IP as well in the config entry (["127.0.0.1:3421"] for example)? Ports below 1024 are privileged so you need to run the server with sudo to use them.

@nynjardin
Copy link
Author

nynjardin commented Jan 5, 2025

@Repflez If I set the ip:port like your example, the HTTP server don't start at all. (same if the server is run in admin or not)

Edit: I have also tested "HTTPListen": ["127.0.0.1", 3421] and only port number like suggested in the comment in config.json file

image

@fuzziqersoftware
Copy link
Owner

My config.json has the line "HTTPListen": [5050], which is the correct syntax. So if you put 3421 instead of 5050, that should also work.

What happens when you set HTTPListen to [3421] in your config.json, run the server, and then in a separate terminal, run curl -vvv http://127.0.0.1:3421/?

@nynjardin
Copy link
Author

My config.json has the line "HTTPListen": [5050], which is the correct syntax. So if you put 3421 instead of 5050, that should also work.

What happens when you set HTTPListen to [3421] in your config.json, run the server, and then in a separate terminal, run curl -vvv http://127.0.0.1:3421/?

I got this:

  • Trying 127.0.0.1:3421...
  • Connected to 127.0.0.1 (127.0.0.1) port 3421

GET / HTTP/1.1
Host: 127.0.0.1:3421
User-Agent: curl/8.9.1
Accept: /

  • Request completely sent off

And nothing else

What -vvv mean?

@fuzziqersoftware
Copy link
Owner

-vvv requests verbose output from curl, so we can see what's going on.

There was a bug a while ago that caused HTTP requests to hang, but I believe this was fixed in a more recent release. Which version of newserv are you using?

@nynjardin
Copy link
Author

-vvv requests verbose output from curl, so we can see what's going on.

There was a bug a while ago that caused HTTP requests to hang, but I believe this was fixed in a more recent release. Which version of newserv are you using?

I use the last released one (2024-11-11)

@kotori
Copy link

kotori commented Jan 5, 2025

@nynjardin Your endpoint is not returning a valid response.
I am using the latest version from git with phosg and the resources dasm.

Here is an example of what a valid request to the API looks like via curl.
(I am using -Lv for an example here as I typically use these two for debugging, one is for follow any redirects and the other just for debugging output).

~$ curl -Lv localhost:2828
*   Trying 127.0.0.1:2828...
* Connected to localhost (127.0.0.1) port 2828 (#0)
> GET / HTTP/1.1
> Host: localhost:2828
> User-Agent: curl/7.88.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: application/json
< Server: newserv
< Date: Sun, 05 Jan 2025 21:40:16 GMT
< Content-Length: 261
<
* Connection #0 to host localhost left intact

{"endpoints":["/y/data/ep3-cards","/y/data/ep3-cards-trial","/y/data/common-tables","/y/data/rare-tables","/y/data/rare-tables/<TABLE-NAME>","/y/data/config","/y/clients","/y/proxy-clients","/y/lobbies","/y/server","/y/rare-drops/stream","/y/summary","/y/all"]}

I have the following set:
config.json: "HTTPListen": [2828],

In your newserv.log you should have something like this indicating a successful startup of the HTTP service:
I 1766439 2025-01-05 14:39:26 - [Server] Listening on TCP interface 0.0.0.0:2828 on fd 27 (HTTP)

As well as this when you successfully hit it:
I 1766439 2025-01-05 15:39:27 - [Server] [HTTPServer] / in [handler: 0.000261, serialize: 0.000167, size: 261 bytes]

You can also perform a netstat to ensure the service is up and listening:

# netstat -ntlap | grep 2828
tcp        0      0 0.0.0.0:2828            0.0.0.0:*               LISTEN      1766439/newserv

@nynjardin
Copy link
Author

nynjardin commented Jan 6, 2025

@kotori

curl -Lv localhost:2828

I don't have this result at all, and sometime, if I perform this command only, the server crash (1 time of 5 maybe) if I wait to much to do ctrl+c in the console who try the curl command.

@kotori
Copy link

kotori commented Jan 7, 2025

I've never seen the application do that. Ever. So you should likely recompile from the latest git source, and ensure your permissions are good on the newserv server directory path and give it a try again. I would avoid reusing any config files you had lying around and instead copy new ones from the live repo and use those with your adjustments. You'll know you did it right when you get similar output as I have shown above.
If on the weird chance you do get this same issue after recompiling from the latest source then please share any newserv log output you do have in < code > tags so that it can be analyzed.

@fuzziqersoftware
Copy link
Owner

The HTTP server apparently does not work on Windows due to a threading issue in Cygwin's libevent build that also affected the patch server in the past, and the HTTP server was never tested on Windows. I've applied the same fix to the HTTP server, but it still doesn't work very well. If you can, I'd recommend running newserv on Linux or macOS instead, since it's unlikely that it will be easy to fix this on Windows.

@insanemal
Copy link

insanemal commented Jan 7, 2025 via email

@nynjardin
Copy link
Author

@fuzziqersoftware Ok, I understand that it's "normal", thanks you for these information :)

@insanemal Ok, I'll try to make a linux version you're way, if that not work, i'll create a linux VM

Thanks everyone :)

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

5 participants