1
votes

This is a very simple sails.js project created from command line "sails new my-project". After having created the project, I create a controller, again, using the client tool (sails create controller dispatcher). In the api/controllers folder a new controller is generated ( DispatcherController.js). In this controller I have a simple method that returns a Hello World

function dispatch(req,res){
    res.send('hello world!');
}

Then I open the config/routes.js and enter a custom route

get /test: 'DispatcherController.dispatch'

I start my project. It runs at localhost:1337. Everything works fine. Now from my browser a enter the custom route url:

http://localhost:1337/test

But I am redirected to the default 404 page. Sails could resolve this route. I am completely lost here. How can someone create a custom route pointing to a controller and access it?

see My routes.js file

2
change log level to silly and start sails. check it there are no errors in router or it there are no policies attached to this route.Bonanza
Thank for the answer. In the log I receive these messages: Sending 404 ("Not Found") response View override argument passed to res.view: 404 Serving view at rel path: 404 View root: F:\my-project\viewsTheSoul
So I don't see any meaning full message. It just tells me that I am being redirected to the 404 page. Could it be that there are some restrictions on my local machine?TheSoul
More important log is something like: Binding route :: get /test (POLICY: sth) and any error after that.Bonanza
@seyaobey Your entry in routes.js is in the format 'get /test':'DispatcherController.dispatch' right? I see you have single quotes missing.MjZac

2 Answers

0
votes

Your routes file has 'get /api' not 'get/test' try that first in your browser.

In your controller try 'return res.send...'

You can try a different send call too. 'Res.json(200, {message: success});'

0
votes

in your controller

 dispatch: function(req,res){
         res.send('hello world!');
    }

in routes file

  "GET /test" : "DispatcherController.dispatch",