Added 301 Redirect

This commit is contained in:
斟酌 鵬兄 2016-07-26 10:46:18 +08:00
parent c73aa30c39
commit 11e33600d0
2 changed files with 10 additions and 6 deletions

View File

@ -104,7 +104,6 @@ class Router extends EventEmitter
return false;
}
// Set Route
setRoute( _route, _match )
{
@ -127,18 +126,16 @@ class Router extends EventEmitter
_self.reRoute = true;
_self.emit( "Route" );
}
, redirect: function( target )
, redirect: function( target, perm )
{
Dragonfly.Debug( "Redirect: " + target );
_self.relaying = new RelayPoint( "302", true, target );
_self.relaying = new RelayPoint( perm ? "301" : "302", true, target );
_self.routable = true;
_self.reRoute = true;
_self.emit( "Route" );
}
};
}
}
module.exports = Router;

View File

@ -21,6 +21,7 @@ class WebFrame
var Router = cl.load( "botanss.net.Router" );
var router = new Router( Http );
router.addRoute( "301", false, "301" );
router.addRoute( "302", false, "302" );
router.addRoute( "403", false, "403" );
router.addRoute( "404", false, "404" );
@ -44,11 +45,17 @@ class WebFrame
_self.result = "404 Not Found";
_self.plantResult();
}
, "301": function()
{
res.statusCode = 301;
res.headers[ "Location" ] = router.relaying.params[0];
_self.result = "";
_self.plantResult();
}
, "302": function()
{
res.statusCode = 302;
res.headers[ "Location" ] = router.relaying.params[0];
_self.result = "";
_self.plantResult();
}