pewpewlasers
pewpewlasers

Reputation: 3215

Sails.js non-static routing urls

So I was working with this Sails.js flash message for user registration but then I got into a new issue. So basically I am using the following in the user controller to render non-static content of the user/register.js file to client.

'register': function(req, res){
    res.view();
},

This however means that the address to access the registration page will be http://localhost/user/register. Is it possible to change this url to work with http://localhost/register without webpage redirects (possibly from the above code itself)? This I believe can be handled using custom redirects Custom Routes. But using redirects could be ugly at times?

Upvotes: 2

Views: 641

Answers (2)

OP's solution to the case in the comment.

[I was not able to solve "/user/register": {response: 'notFound'} by sgress454 proposal]. However, turning actions to false in config/blueprints.js did the trick.

Sails version < 0.10.x because the other answer solution should work here.

Upvotes: 0

sgress454
sgress454

Reputation: 24948

You linked to right documentation, but didn't look in the right section. You want to use the controller/action custom route syntax to route /register to the UserController.register action:

"/register": "UserController.register"

or

"/register": {controller: 'user', action: 'register'}

in your config/routes.js will do what you want.

To disable the default /user/register route, you can either 1) set actions to false in config/blueprints.js (this will turn off all default controller/action routing), or explicitly disable the route in config/routes.js:

"/user/register": {response: 'notFound'}

Upvotes: 3

Related Questions