Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

How to add logdebug #37

Closed
39ma opened this issue Apr 25, 2022 · 20 comments
Closed

How to add logdebug #37

39ma opened this issue Apr 25, 2022 · 20 comments
Labels
question Further information is requested

Comments

@39ma
Copy link

39ma commented Apr 25, 2022

How to add logdebug what plugin trying to send to a G5API?

I got a problem with error:

L 04/25/2022 - 19:34:13: [G5WS.smx] [ERR] API request failed, HTTP status code: 500
L 04/25/2022 - 19:34:13: [G5WS.smx] [ERR] Response:
{
    "message": "Not a correct API Key"
}

But when I create a manual POST request from Insomnia program. API responds without errors.

I want to check what request G5WS trying to create, and search for an error.

@39ma
Copy link
Author

39ma commented Apr 25, 2022

And if it is possible is there any way to check what G5API receiving.

@PhlexPlexico
Copy link
Owner

PhlexPlexico commented Apr 25, 2022

If you'd like to on the game server you can call get5_debug 32 and it should output some values from the LogDebug calls. If you're getting that error, that tends to mean there may be an issue in configuring your reverse proxy, or there is empty body requests being sent. See this issue for a possible similar problem. What you can do is add some console.log(req.body); in the API calls (located in legacy/api.js) as well, but I would try using the full docker-compose file if you haven't already and see if that receives data.

There was another issue at one point as well here that was running into a similar issue, where Windows Game servers are not able to send data, however I think that has been patched in the latest release of sm-ripext.

Thanks!

@PhlexPlexico PhlexPlexico added the question Further information is requested label Apr 25, 2022
@39ma
Copy link
Author

39ma commented Apr 25, 2022

Thank you! I'll try to use docker as linked issue.
Tested that empty body request is coming to G5API.
But it is strange, because if I send manual API Request from Insomnia client, G5API gets full body request

@PhlexPlexico
Copy link
Owner

What web server are you using if I may ask? There may be some common issue here if it's nginx, and it may be something worth looking into more, as I think that may be the problem.

Thanks!

@39ma
Copy link
Author

39ma commented Apr 25, 2022

nginx version: nginx/1.14.0 (Ubuntu)

@39ma
Copy link
Author

39ma commented Apr 25, 2022

##
# Default server configuration
#
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        # This is where the build for G5V resides, update this to wherever you need.
        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        # Change this to whichever hostname you have, such as get5.phlexplexi.co
        server_name tour.39ma.ru;

        # This is the main block that was added. Currently the API runs on port 3301. You may adjust to what you need it to if you changed ports in the config.
        location /api/ {
                proxy_pass http://localhost:3301/;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }

        # IF YOU'RE USING THE DOCKER IMAGE, THIS WILL HAVE TO BE UPDATED IN THE DOCKER IMAGE ITSELF. Do not put this on your reverse proxy.
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri /index.html;
        }


        # pass PHP scripts to FastCGI server
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
        #       fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}

@39ma
Copy link
Author

39ma commented Apr 25, 2022

Still got a problem with docker too. Manually added to docker container a console.log(req.body); in api.js

image

and this is from insomnia

image

so I think problem, not in reverse proxy. Because same error in Caddy and nginx. Game plugin sends empty body

image
image

@PhlexPlexico
Copy link
Owner

I think I may have something to test here - would you mind trying to get the data sent over HTTPS? You may have to get a cert from LetsEncrypt for your website, but try doing that and see if the data gets sent?

Thanks!

@39ma
Copy link
Author

39ma commented Apr 26, 2022

No matter in docker or nginx? Because to add SSL to nginx is not a problem, but idk how to do it in docker

@39ma
Copy link
Author

39ma commented Apr 26, 2022

didn't helped in nginx. I have installed lets encrypt certificate, and changed http to https in configs, still an error.
But strange that with your api https://phlex.avidgamers.me/ everything works fine.

@39ma
Copy link
Author

39ma commented Apr 26, 2022

Found this line in nginx logs

194.4.57.34 - - [26/Apr/2022:07:51:24 +0000] "{\x22key\x22: \x22M0AW5SZAJCIOV1HFO6SHIGD7\x22, \x22winner\x22: \x22none\x22, \x22team1score\x22: 0, \x22team2score\x22: 0, \x22forfeit\x22: 0}" 400 182 "-" "-"

Is it normal that in log it use \x22? May be because of this format nginx proxy don't pass it to api?

@39ma
Copy link
Author

39ma commented Apr 26, 2022

Switched from nginx to Caddy. Used a config from https://github.com/PhlexPlexico/G5V/wiki/Webserver-Setup-With-Caddy, and now it works.

@PhlexPlexico
Copy link
Owner

Hmmm how did you end up getting that log from nginx? This might be something definitely looking into. My public panel is currently using NGINX behind an NGINX (reverse-reverse proxy lol) proxy... Could you try one more thing with your NGINX config for me, please? Under the location /api/ block could you add this - default_type application/json; inside it? I want to see if that makes any difference. If not, I may try appending that header in the calls in the plugin as well... This is super helpful actually, thanks for showing this!

@39ma
Copy link
Author

39ma commented Apr 26, 2022

Ok I'll check it later and write it here
I found this in /var/log/nginx/access.log it is from sm-rip
When I make special error in insomnia it doesn't show up in this log and comes to API.
Idk why this could be.

@PhlexPlexico
Copy link
Owner

Are you hitting the API port directly? I.e. yourserver.com:3301 when posting with Insomnia?

Also, another thing to test would be to remove the reverse proxy completely. In all your settings, instead of having /api for your API end point, you can change them to your server directly (yourserver.com:3301 instead of yourserver.com/api) and open that port temporarily and test, see if that's working as intended? If so, it definitely is something to do with NGINX. I know from a quick Google that the hexadecimal may just be a logging thing, but I'm not sure why that body isn't getting sent...

Thanks!

@39ma
Copy link
Author

39ma commented Apr 26, 2022

No, to domain.com/api threw nginx from Insomnia

@39ma
Copy link
Author

39ma commented Apr 26, 2022

Also, another thing to test would be to remove the reverse proxy completely. Ok I'll do that test too.
I know from a quick Google that the hexadecimal may just be a logging thing. Yeah was reading about this too. But strange that this body gets error 400 (Bad request) and not going to API

@PhlexPlexico
Copy link
Owner

If you try and set the application type it may help... It's good to see that it's at least making it to the reverse proxy, but not to the express app, which leads me to believe the content type may not be getting set, in which case I could make a change to the plugin as well to ensure the Content-Type is correct, or just add it into the wiki config :)

Thanks for helping me out with this, it's much appreciated!

@39ma
Copy link
Author

39ma commented Apr 26, 2022

Yeah of course I'll help at testing, its not a problem, but after work :)
Thank you and other guys who helping, for this good project and great feedback!

@PhlexPlexico
Copy link
Owner

As there hasn't been any response or updates in 20 days, will close this now. If you need to reopen, feel free to let me know!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants