0

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

请帮忙

4

1 回答 1

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

于 2015-01-20T13:21:19.420 回答