Skip to content

Make nginx reverse proxy conf work with Turbolinks

Stan Hu requested to merge fix-nginx-conf-for-turbolinks into master

Not having this config causes Turbolinks to store the internal host/port in X-XHR-Redirected-To, which causes the GitLab import redirection to fail with such messages as the following:

Uncaught SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL 'http://localhost:4000/test/vgstation' cannot be created in a document with origin 'http://localhost:3000'.

The code in question from Turbolinks:

reflectRedirectedUrl = function() {
    var location, preservedHash;
    if (location = xhr.getResponseHeader('X-XHR-Redirected-To')) {
      location = new ComponentUrl(location);
      preservedHash = location.hasNoHash() ? document.location.hash : '';
      return window.history.replaceState(window.history.state, '', location.href + preservedHash);
    }
  };

The X-XHR-Redirected-To field shows the internal Rails configuration unless special nginx configuration is used to mask this. These settings are modeled after omnibus-gitlab.

Merge request reports