0

I am using nodejs and used the locomotivejs as a MVC Framework.. I am working in my local and when i access the url of users contrell, it will display my data..

However the problem is when i deployed it to my server using git repository, and when i access the users url like this : http://106.xx.xx.x:3000/users/, it says this error :

        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

This only happens in the server, not in my local...

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

    }

This is my 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);

            };

Whats the problem with locomotive? How can i fix this?

Note : I am using git to migrate my files to my server..

Please help

Bogz
  • 565
  • 1
  • 10
  • 30

1 Answers1

0

I think you need to create a new Controller like this:

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;

And make sure your file name is users_controller.js which should in directory /yourproject/app/controllers

ScorpioCPH
  • 151
  • 2
  • 8