Page loads blank until refresh

NodeBB Development
  • Hey there my forum is running on /forum thanks to nginx, but I have this behavior where when I follow any NodeBB link (e.g. click on a category) the page first loads blank, but appears perfectly if I refresh/reload. The page isn't totally blank initially, but I see the loading circle graphic.

    The only things I see in inspector is the socket.io polling and an error that doesn't exist if I refresh.

    Console error:

    ajaxify.js:84 Uncaught TypeError: Cannot read property 'name' of undefined
        at ajaxify.js:84
        at Object.success (ajaxify.js:407)
        at c (jquery.js:3500)
        at Object.fireWith [as resolveWith] (jquery.js:3630)
        at E (jquery.js:9796)
        at XMLHttpRequest.<anonymous> (jquery.js:10057)
    

    Thanks!

  • What is your url in config.json? Does it have /forum?

  • Hmm it doesn't!

    {
        "url": "http://localhost:4567",
        "secret": "secret",
        "database": "redis",
        "port": "4567",
        "redis": {
            "host": "127.0.0.1",
            "port": "6379",
            "password": "",
            "database": "0"
        }
    }
    

    Changing it to where it actually loads:
    "url": "http://localhost/forum",
    or
    "url": "http://localhost:4567/forum",

    Causes this error when I refresh the forum.

    (node:62717) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'sessionSharing' of undefined
        at Object.plugin.appendTemplate [as method] (/Users/mikebaker/access/NodeBB/node_modules/nodebb-plugin-session-sharing/library.js:636:23)
        at /Users/mikebaker/access/NodeBB/src/plugins/hooks.js:140:29
        at new Promise (<anonymous>)
        at fireMethod (/Users/mikebaker/access/NodeBB/src/plugins/hooks.js:130:10)
        at Object.fireFilterHook [as filter] (/Users/mikebaker/access/NodeBB/src/plugins/hooks.js:159:18)
        at Hooks.fire (/Users/mikebaker/access/NodeBB/src/plugins/hooks.js:99:49)
        at Object.wrapperCallback [as fire] (/Users/mikebaker/access/NodeBB/src/promisify.js:46:11)
        at ServerResponse.renderOverride [as render] (/Users/mikebaker/access/NodeBB/src/middleware/render.js:42:45)
        at processTicksAndRejections (internal/process/task_queues.js:97:5)
        at async Object.exports.send404 (/Users/mikebaker/access/NodeBB/src/controllers/404.js:63:2)
    (node:62717) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
    (node:62717) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
    
    
  • Seems like it breaks when I remove :4567 from the URL. Otherwise it's happy.

  • Cracked it! I had all this nonsense in my nginx from googling around. here is what worked.

    location /forum {
                if ($request_method = 'OPTIONS') {
                    add_header 'Access-Control-Allow-Origin' '*';
    
                    add_header 'Access-Control-Allow-Credentials' 'true';
                    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                    add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-AUTHENTICATION, X-IP, Accept';
                    add_header 'Access-Control-Max-Age' 1728000;
                    add_header 'Content-Type' 'text/plain charset=UTF-8';
                    add_header 'Content-Length' 0;
                    return 204;
                }
                if ($request_method = 'POST') {
                    add_header 'Access-Control-Allow-Origin' '*';
                    add_header 'Access-Control-Allow-Credentials' 'true';
                    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                    add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-AUTHENTICATION, X-IP, Accept';
                    
                }
                if ($request_method = 'GET') {
                    add_header 'Access-Control-Allow-Origin' '*';
                    add_header 'Access-Control-Allow-Credentials' 'true';
                    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                    add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-AUTHENTICATION, X-IP, Accept';
                    
                }
    
                add_header 'Access-Control-Allow-Credentials' 'true';
                add_header X-Frame-Options "SAMEORIGIN";
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header Host $http_host;
                proxy_set_header X-NginX-Proxy true;
               # proxy_set_header        X-Forwarded-Proto $http_x_forwarded_proto;
    
               
                proxy_pass http://127.0.0.1:4567;  # no subfolder defined here
                proxy_set_header Host $host; # MAGIC
                proxy_redirect off;
                
                
                # Socket.IO Support
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
    
    
            }
    

Suggested Topics