Node.js& Partial.js从控制器重定向

时间:2014-08-07 04:19:13

标签: node.js

我有这个:

exports.install = function (framework) {
    framework.route('/CreateRoom', redirect_createroom);
};

function redirect_createroom() {
    var roomId = 10000;
    response.writeHead(301, {'Location': 'Room/' + roomId});
    response.end();
}

当我去localhost:8182 / CreateRoom时,我收到错误:

ReferenceError: response is not defined ReferenceError: response is not defined
    at Object.redirect_createroom (/Users/ec/Desktop/EPNodeJs/controllers/default.js:21:5)
    at Subscribe._execute (/Users/ec/Desktop/EPNodeJs/node_modules/partial.js/index.js:3:19370)
    at Subscribe.execute (/Users/ec/Desktop/EPNodeJs/node_modules/partial.js/index.js:3:17657)
    at Subscribe.prepare (/Users/ec/Desktop/EPNodeJs/node_modules/partial.js/index.js:3:18828)
    at Subscribe._end (/Users/ec/Desktop/EPNodeJs/node_modules/partial.js/index.js:3:21003)
    at IncomingMessage.emit (events.js:92:17)
    at _stream_readable.js:938:16
    at process._tickCallback (node.js:419:13)

我已经搜索过,但没有找到这个问题的答案。

该控制器使用partial.js实现。我无法在标签中添加此信息,因为我没有适当的级别。

由于 即

1 个答案:

答案 0 :(得分:0)

应该使用this在控制器中进行重定向。

例如:

this.redirect('Room/'+roomId);

文档和域名已移至totaljs