src/redirect.js

Method redirect

Redirects GETs for a route to another URL

Parameters:

  • route must be a String.
    (Route to redirect)

  • url must be a String.
    (URL to redirect the Client to)

  • host must be a String.
    ([Optional] Hostname this route is for (default is all))

  • permanent must be a Boolean.
    ([Optional] true will indicate the redirection is permanent)

Returns an Object
(instance)

TurtleIO.prototype.redirect = function ( route, url, host, permanent ) { var code = this.codes[permanent === true ? "MOVED" : "REDIRECT"], pattern = new RegExp( "^" + route + "$" ); this.get( route, function ( req, res ) { var rewrite = ( pattern.exec( req.url ) || [] ).length > 0; this.respond( req, res, this.messages.NO_CONTENT, code, {"Location": ( rewrite ? req.url.replace( pattern, url ) : url )} ); }, host); return this; };