无法解析控制器 - locomotivejs(nodejs)

时间:2015-01-08 10:03:37

标签: node.js controller locomotivejs

我正在使用nodejs并将locomotivejs用作MVC框架。 我在我的本地工作,当我访问用户contrell的网址时,它将显示我的数据..

然而问题是当我使用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

    }

这是我的UsersController

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将我的文件迁移到我的服务器..

请帮忙

1 个答案:

答案 0 :(得分:0)

我认为你需要像这样创建一个新的控制器:

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