Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I split router.js in SailsJS

My project is getting larger and router.js is growing too. Is it possible to split it into several different route files? Each route file applies to a different controller.

like image 393
Ivan No Avatar asked Feb 04 '15 14:02

Ivan No


People also ask

What is sails JS?

Sails.js is a Node.js framework that allows you to build enterprise-ready, custom MVC ( model, view, controller ) application on-the-go. Sails.js has built-in features such as an API creator, and its socket integration in every route and database ORM makes it very useful and helps speed up development.

How do I route URLs in sails?

Sails allows you to explicitly route URLs in several different ways in your config/routes.js file. Every route configuration consists of an address and a target, for example: The route address indicates what URL should be matched in order to apply the handler and options defined by the target.

What is a router in sails?

Like most web frameworks, Sails provides a router: a mechanism for mapping URLs to actions and views. Routes are rules that tell Sails what to do when faced with an incoming request. There are two main types of routes in Sails: custom (or "explicit") and automatic (or "implicit").

How to secure your project with sails JS?

Furthermore, common security parameters such as CORS and CSRF are already included in Sails.js project. All you need to do is to enable them from respective files and your application is secured with the latest security standards.


1 Answers

In sails, you can put your routes in any file in config/, as long as you export module.exports.routes. So you can do something like this:

1. config/routes.js

module.exports.routes = { };

2. config/routes/otherRoute.js

_.defaults(sails.config.routes, {
  // other routes
});
like image 96
Travis Webb Avatar answered Jan 01 '23 14:01

Travis Webb