【发布时间】:2016-07-26 18:11:34
【问题描述】:
我正在开发的 nodejs 应用程序是使用 express 和 路由中间件。我正在添加某种许可功能 此应用程序会定期检查是否过期。
发现过期后,发出授权失败事件 在事件处理程序中捕获。我想重定向或打开一个新页面 在事件处理程序中。
- 这是正确的方法吗? (我是 node 和 js 的新手)
-
我无权访问事件处理程序中的响应对象。 那么在这种情况下我如何重定向到不同的页面?
//Start of the code var app = express(); //view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); //Deleted the code to keep it minimal app.use('/', routes); app.use('/sensor', sensorPage); app.use('/export', exportPage); app.use('/exportsensormetrics', exportSensorMetricsPage); //Error Handling app.use(function(req, res, next) { var err = new Error('Not Found'); err.status = 404; next(err); }); //The product key authorise() function periodically checks for expiry var authutils = require('./authutils.js'); authutils.authorise(); //This is the Event Handler authutils.authEvent.on('authorisation', function(data) { if(data == 'passed') { utils.dump("authutils::authEvent::on: Authorisation Passed"); } else if(data == 'failed') { //Auth failed //I want to redirect from here and open page which says expired //Can I redirect from here? } });
【问题讨论】:
标签: javascript node.js redirect express