Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect protocol and host #150

Merged
merged 7 commits into from
Nov 13, 2017
Merged

Conversation

joanniclaborde
Copy link
Contributor

@joanniclaborde joanniclaborde commented Nov 6, 2017

Adds ability to redirect from and to a specific protocol and/or host. It is now possible to use objects for the from and to properties in redirects.js.

If a from object is used (instead of the usual string or regular expression), the following properties are available:

  • protocol - If specified, the request's protocol must match for the whole redirect to match (http or https).
  • host - If specified, the request's host must match for the whole redirect to match (for example site.com).
  • path - The path to match, this is the same as the original from. Defaults to *, to match all paths.

If a to object is used (instead of the usual string or function), the following properties are available:

  • protocol - If specified, will override the request's protocol.
  • host - If specified, will override the request's host.
  • url - The url to redirect to, this is the same as the original to. Defaults to the request's url.

Example to automatically redirect to HTTPS and from the root domain to the www subdomain:

// redirects.js
exports = [
  // http://site.com => https://www.site.com, will preserve the url
  {
    from: {
      protocol: 'http',
      host: 'site.com'
    },
    to: {
      protocol: 'https',
      host: 'www.site.com'
    }
  },
  // http://www.site.com => https://www.site.com, will preserve the url
  {
    from: {
      protocol: 'http',
      host: 'www.site.com'
    },
    to: {
      protocol: 'https'
    }
  }  
];

Copy link
Member

@pushred pushred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Straightforward.

package.json Outdated
@@ -23,7 +23,7 @@
"commander": "1.1.x",
"continuation-local-storage": "~3.1.1",
"express": "3.1.x",
"express-expose": "SparkartGroupInc/express-expose#escape-script-ending-tag",
"express-expose": "sparkartgroupinc/express-expose#escape-script-ending-tag",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well use the new org name, sparkartgroup

@@ -116,6 +116,7 @@ var SolidusServer = function( options ){
router.engine( DEFAULT_VIEW_EXTENSION, handlebars.engine );
router.set( 'view engine', DEFAULT_VIEW_EXTENSION );
router.set( 'views', paths.views );
router.set( 'trust proxy', true ); // Use the X-Forwarded-* headers: https://expressjs.com/en/guide/behind-proxies.html
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required by Fastly, or any other CDN?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, the HTTPS protocol doesn't seem to be detected by Solidus on Heroku, so HTTPS requests end up in redirect loops.

@joanniclaborde joanniclaborde merged commit ab7b5f7 into master Nov 13, 2017
@joanniclaborde joanniclaborde deleted the redirect-protocol-and-host branch November 13, 2017 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants