javascript - Node JS redirects give me a bunch of html text -
Ask questions about nodes and redirects, and maybe rendering.
app.js In my app js, I have these codes that work well. Then, error.notFound Increase Routes Dashboard You also work while loading it from the URL Here's the hard part that gives me some error. Authorization Heller This method will check if the user is allowed to view the page or else it will redirect. > The problem is, everything works properly on this res.redirect ('/ error / 401') and sometimes, on the server, this page But instead, this will provide a full bunch of HTML text and some headers! ! Please help! You to and This will prevent rendering your dashboard in case of unauthorized access. In addition, you may want to consider centralizing your error handling so that you have an error handler middleware (
app.get ('/ dashboard', routes.dashboard); App.get ('/ error / 404', error.notFound);
export.illegal = function (req, res) {var authLevel = ''; Var entityName = ''; Var entityId = ''; Var deviceId = ''; If (req.Session.authorizationLevel) authLevel = req.session.authorizationLevel; If (req.session.name) entityName = req.session.name; If (req.session.entityId) entityId = req.session.entityId; If (req.session.deviceId) deviceId = req.session.deviceId; Res.render ('error / invalid', {title: 'illegal', viewClass: 'illegal', ngController: '', entity name: entity name, entity id: entity id, device id: device id, authorization: level : AuthLevel}); };
exports .dashboard = Function (req, res) {// method for authentication, see below. This is giving me the error Authorization Helper.AuthorizationLevels (req, res, 400); Var authLevel = ''; Var entityName = ''; Var entityId = ''; Var deviceId = ''; If (req.Session.authorizationLevel) authLevel = req.session.authorizationLevel; If (req.session.name) entityName = req.session.name; If (req.session.entityId) entityId = req.session.entityId; If (req.session.deviceId) deviceId = req.session.deviceId; Res.render ('dashboard', {title: 'dashboard', visual class: 'dashboard', ng controller: 'dashboard controller', entity name: entity name, entity id: entity id, device id: device id, authorization: Level: authLevel}); };
Method for authorization, see below it is giving me the error Authorization Helper.AuthorizationLevels (req, res, 400);
exports.authorizationLevels = function (req, res, levelRequired) {if (req.session.authorizationLevel & lt; levelRequired ||! Req.session.authorizationLevel) {// user is not allowed to view page Is an invalid redirect page, res.redirect ('/ error / 401'); }}
export.authorizationLevels = function (req, res, LevelRequired) {If (req.session.authorizationLevel & lt; levelRequired ||! Req.session.authorizationLevel) {// user is not allowed to view page, invalid page res.redirect ('/ error / 401 '); }}
export.authorizationLevels = function (req, res, levelRequired) {if (req.session.authorizationLevel & lt; levelRequired || ! Req.session.authorizationLevel) {// User does not have permission to view page, Restricted to illegal page. Rdirect ('/ error / 401'); return false; } Back true; }
authorization. Helper.authorizationLevels (req, res, 400);
if (authorization. Assistant authorization level (request, ridge, 400)) return;
(err, req, res, next) ) and there Rendering error templates (whereas just
forward (401); and errors in your root handler), as long as you have them in the
/ error / 401 Do not want to see
Comments
Post a Comment