cocos2d / cocos2d-x-docs

documentation of cocos2d-x
102 stars 65 forks source link

Bug when trailing slash on the live page #292

Closed mrexodia closed 4 years ago

mrexodia commented 4 years ago

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/
slackmoehrle commented 4 years ago

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

slackmoehrle commented 4 years ago

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
mrexodia commented 4 years ago

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.

slackmoehrle commented 4 years ago

I’ll test with Chrome. I can’t reproduce this. I’ll make a video of what I’m doing so you can see

On Jan 13, 2020, at 8:05 AM, Duncan Ogilvie notifications@github.com wrote:

 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.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

mrexodia commented 4 years ago

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...

slackmoehrle commented 4 years ago

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

slackmoehrle commented 4 years ago

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.

mrexodia commented 4 years ago

I think it’s related to the way the redirect is communicated to the browser by the server. See my earlier curl examples. With a clean cache this issue still happens and it works perfectly when using gitbook serve, so it must be related to the server response I’d say...

On Mon, 13 Jan 2020 at 19:34, Slack-Moehrle notifications@github.com wrote:

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.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/cocos2d/cocos2d-x-docs/issues/292?email_source=notifications&email_token=AASYFGKUDQQCNZNAI5EFXHLQ5SXZXA5CNFSM4KFHGWHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIZZNSY#issuecomment-573806283, or unsubscribe https://github.com/notifications/unsubscribe-auth/AASYFGMQ2JROBAELQT7PW4LQ5SXZXANCNFSM4KFHGWHA .

mrexodia commented 4 years ago

Could you somehow share your deployment scripts or method and server configuration. I could then try to reproduce the issue with “realistic” parameters.

On Mon, 13 Jan 2020 at 19:44, Duncan Ogilvie mr.exodia.tpodt@gmail.com wrote:

I think it’s related to the way the redirect is communicated to the browser by the server. See my earlier curl examples. With a clean cache this issue still happens and it works perfectly when using gitbook serve, so it must be related to the server response I’d say...

On Mon, 13 Jan 2020 at 19:34, Slack-Moehrle notifications@github.com wrote:

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.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/cocos2d/cocos2d-x-docs/issues/292?email_source=notifications&email_token=AASYFGKUDQQCNZNAI5EFXHLQ5SXZXA5CNFSM4KFHGWHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIZZNSY#issuecomment-573806283, or unsubscribe https://github.com/notifications/unsubscribe-auth/AASYFGMQ2JROBAELQT7PW4LQ5SXZXANCNFSM4KFHGWHA .

slackmoehrle commented 4 years ago

This is what I run to deploy: https://github.com/cocos2d/cocos2d-x-docs-deps/blob/Q3-2019-1/deploy-cocos2dx.sh

mrexodia commented 4 years ago

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

mrexodia commented 4 years ago

I found this: https://github.com/GitbookIO/gitbook/commit/5f3de0876fd33f77df0eb3ccccd1f964e3a811bc which seems to fix this issue for gitbook serve (which is also what the curl things I did earlier show).

slackmoehrle commented 4 years ago

it's like this, minus ssl:

server {
listen 80;
server_name docs.cocos2d-x.org;
return 301 https://docs.cocos2d-x.org$request_uri;
}

server {
listen 443 ssl;
server_name docs.cocos2d-x.org;

root /var/www/documentation;
index index.html;

gzip on;
gzip_vary on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript
application/x-javascript application/xml;
gzip_disable "MSIE [1-6]\.";

access_log /var/log/docs.cocos2d-x.org.access.log;
error_log /var/log/docs.cocos2d-x.org.error.log;
mrexodia commented 4 years ago

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...

mrexodia commented 4 years ago

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;
slackmoehrle commented 4 years ago

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.

mrexodia commented 4 years ago

It looks like everything is working correctly now, thanks!

slackmoehrle commented 4 years ago

No thank you! Thanks for helping research and find a solution.

On Jan 14, 2020, at 5:28 AM, Duncan Ogilvie notifications@github.com wrote:

 It looks like everything is working correctly now, thanks!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.