0

私はnodejsを使用しており、locomotivejsをMVCフレームワークとして使用しています..私はローカルで作業しており、ユーザーコントロールの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

    }

これは私の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を使用してファイルをサーバーに移行しています..

助けてください

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 に答える