cocos2d/cocos2d-x-docs

Bug when trailing slash on the live page

mrexodia opened this issue · 18 comments

If you go to:

https://docs.cocos2d-x.org/cocos2d-x/v4/en/basic_concepts/

You have the link installation docs, which does not contain a trailing / in the link. This is fine if you manually go there (because the / is added by a redirect), but if you click through on the same page there will be corrupt links.

For example the Android Studio link points to https://docs.cocos2d-x.org/cocos2d-x/v4/en/Android-Studio.html, which does not exist (the /installation/ is missing). I guess this behavior is related to iframes, but it happens in both Chrome and Opera and is quite confusing for a new user trying to install. I tried to inspect the network traffic and I have absolutely no idea.

See below for what I mean:

2020-01-10_13-37-30

>curl https://docs.cocos2d-x.org/cocos2d-x/v4/en/installation
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>

It looks like for some reason the redirect with the trailing / is ignored. My proposed solution: modify gitbook's configuration to always emit the / as part of the link to avoid this bug altogether.

When using gitbook serve everything is working properly so here are both the raw requests:

C:\Users\Duncan>curl -D - https://docs.cocos2d-x.org/cocos2d-x/v4/en/installation
HTTP/1.1 301 Moved Permanently
Server: nginx/1.16.1
Date: Fri, 10 Jan 2020 12:50:43 GMT
Content-Type: text/html
Content-Length: 169
Location: https://docs.cocos2d-x.org/cocos2d-x/v4/en/installation/
Connection: keep-alive

<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>

C:\Users\Duncan>curl -D - http://localhost:4000/en/installation
HTTP/1.1 301 Moved Permanently
X-Current-Location: /en/installation
Location: /en/installation/
Date: Fri, 10 Jan 2020 12:50:56 GMT
Connection: keep-alive
Content-Length: 32

Redirecting to /en/installation/

thank you. I will fix this today and re-deploy the docs.

I've tried to find this bug, but when I follow the URL you provide everything contains the /installation/ directory.

Screen Shot 2020-01-12 at 18 56 38

If you follow https://docs.cocos2d-x.org/cocos2d-x/v4/en/installation it will work, because you are redirected to ../installation/. This issue only happens if you go to https://docs.cocos2d-x.org/cocos2d-x/v4/en/basic_concepts/ and normal click (eg not open in new tab) on the installation docs link. I tested in Chrome. If you click on the installation link and then refresh the page everything works too.

I also tested and it's causing this problem so far in Chrome, Firefox and Opera (with various different PCs, also with a clean cache). Very strange indeed...

I can now reproduce this. I tried to make a ,gif but it failed. I uploaded a .mov here:

https://www.icloud.com/iclouddrive/0b8IjnztdO69QtVOR2UwTVKcA#url_bug

ok, I tried removing the trailing / and re-deploying but that didn't help fix. It is so weird. Perhaps there is a caching issue because if I refresh the page the links work.

So that's basically just gitbook build. And what is the nginx configuration (roughly)?

I found this: GitbookIO/gitbook@5f3de08 which seems to fix this issue for gitbook serve (which is also what the curl things I did earlier show).

With Caddy I also encountered this issue and this fixed everything for me:

http://localhost:4040/ {
    root "c:\cocos2d-x-docs\_book"
    header / X-Current-Location "{path}/"
}

I will try to reproduce things with nginx, but I am not as familiar with it, so bear with me...

My nginx.conf:

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       4050;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   ../_book;
            index  index.html index.htm;

            set $current_location $uri;
            if ($uri ~ ^(.+)index.html?$) {
                set $current_location $1;
            }
            add_header X-Current-Location $current_location;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

}

I figured out that you have to set X-Current-Location to whatever the current location is (surprise lol). The useful part:

            set $current_location $uri;
            if ($uri ~ ^(.+)index.html?$) {
                set $current_location $1;
            }
            add_header X-Current-Location $current_location;

ok, so I read up on this and read your reply and I think this is fixed now. Can you please try testing on your end? I tested in Firefox and Chrome.

It looks like everything is working correctly now, thanks!