我正在使用nodejs,并使用locomotivejs作为MVC框架。我正在本地工作,当我访问用户 contrell 的 url 时,它将显示我的数据。
但是,问题是当我使用 git 存储库将其部署到我的服务器时,当我像这样访问用户 url 时: http://106.xx.xx.x:3000/users/,它说这个错误:
Express
500 DispatchError: Unable to resolve controller 'users'
at Application._controller (/var/www/html/myapp/node_modules/locomotive/lib/application.js:270:17)
at dispatch (/var/www/html/myapp/node_modules/locomotive/lib/middleware/dispatch.js:13:9)
at callbacks (/var/www/html/myapp/node_modules/express/lib/router/index.js:164:37)
at param (/var/www/html/myapp/node_modules/express/lib/router/index.js:138:11)
at pass (/var/www/html/myapp/node_modules/express/lib/router/index.js:145:5)
at Router._dispatch (/var/www/html/myapp/node_modules/express/lib/router/index.js:173:5)
at Object.router (/var/www/html/myapp/node_modules/express/lib/router/index.js:33:10)
at next (/var/www/html/myapp/node_modules/express/node_modules/connect/lib/proto.js:174:15)
at methodOverride (/var/www/html/myapp/node_modules/express/node_modules/connect/node_modules/method-override/index.js:77:5)
at /var/www/html/myapp/node_modules/express/node_modules/connect/lib/middleware/methodOverride.js:41:7
at Application._controller (/var/www/html/myapp/node_modules/locomotive/lib/application.js:270:17)
at dispatch (/var/www/html/myapp/node_modules/locomotive/lib/middleware/dispatch.js:13:9)
at callbacks (/var/www/html/myapp/node_modules/express/lib/router/index.js:164:37)
at param (/var/www/html/myapp/node_modules/express/lib/router/index.js:138:11)
at pass (/var/www/html/myapp/node_modules/express/lib/router/index.js:145:5)
at Router._dispatch (/var/www/html/myapp/node_modules/express/lib/router/index.js:173:5)
at Object.router (/var/www/html/myapp/node_modules/express/lib/router/index.js:33:10)
at next (/var/www/html/myapp/node_modules/express/node_modules/connect/lib/proto.js:174:15)
at methodOverride (/var/www/html/myapp/node_modules/express/node_modules/connect/node_modules/method-override/index.js:77:5)
at /var/www/html/myapp/node_modules/express/node_modules/connect/lib/middleware/methodOverride.js:41:7
这只发生在服务器中,而不是在我的本地......
module.exports = function routes() {
this.root('pages#main');
this.match("songs/:title", "songs#show");
// Users
this.match("users/login", "users#login", {via : "GET"});
this.match("users/register", "users#register", {via : "POST"});
this.match("users/verify", "users#verify", {via : "GET"});
this.match("users/verified", "users#verified", {via : "GET"});
this.match("users/test", "users#test", {via : "GET"});
this.match("users", "users#index", {via : "GET"});
this.match("users/:user_id/:atoken", "users#show", {via : "GET"});
// Runs
this.match("runs/:run_id/:atoken", "runs#show", {via : "GET"});
this.match("runs/create", "runs#create", {via : "POST"}); // POST
}
这是我的用户控制器
var UsersController = require('./base/BaseController');
var UsersModel = require('../models/UsersModel');
UsersController.test = function() {
var app = this.app;
console.log("TES CONTROLLER");
console.log(__dirname + '../../public/images/uploads/users/');
console.log(app.pathUtil.join(__dirname, '../../public/images/uploads/users/'));
console.log(app.pathUtil.join('/foo', 'bar', 'baz/asdf', 'quux', '..'));
//this.render();
}
UsersController.index = function() {
var app = this.app;
this._construct(app);
app.res.handleGetResults = function(app, data) {
console.log("handleGetResults");
app.res.json(data);
}
UsersModel.getUsers(app);
};
机车有什么问题?我该如何解决这个问题?
注意:我正在使用git将我的文件迁移到我的服务器。
请帮忙
我认为您需要像这样创建一个新的控制器:
var locomotive = require ('locomotive');
var Controller = locomotive.Controller;
var UsersController = new Controller ();
UsersController.test = function() {
.... add your code here ....
}
// then exports this controller
module.exports = UsersController;
并确保您的文件名users_controller.js
应该在目录/yourproject/app/controllers