New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

sails-controller-driven-routing

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sails-controller-driven-routing

A routing configuration similar to blueprint that reads the routes from the controller so everything is kept in one place

  • 1.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
increased by57.14%
Maintainers
1
Weekly downloads
 
Created
Source

sails-controller-driven-routing

Build Coverage Quality Dependencies A routing configuration similar to blueprint that reads the routes from the controller so everything is kept in one place

It relies on blueprints validating your configuration (because I didn't want to copy/paste), but you could maybe disable blueprints entirely in production if you're feeling courageous and don't need any of its helpers.

Motivation

  • I wanted to support have a controller that has n accessible points
  • I wanted to export my private methods to allow for easy testing (I just discovered Rewire so that's probably no longer true).
  • I didn't want those private methods to be exposed to http
  • I wanted to keep all the configuration in the controller rather than updating the routing.js
  • I wanted to handle multiple HTTP verbs without having to have a switch() at the top of each exposed method.

Usage

$ npm instal sails-controller-driven-routing Your controller can now look like the following:

MyController.js

module.exports = {
  _config: {
    actions: false, //disable built in blueprints
    shortcuts: false, //disable built in blueprints
    rest: false, //disable built in blueprints
    explicitRoutes: {
      'OPTIONS /hello/world': 'mycontroller.world'
    },
    exposedMethods: [
      'foobar'
    ]
  },
  world: function(res, req) {
    return res.ok("hello");
  },
  foobar: function(res, req) {
    return res.ok("bar");
  },
  foobarPost: function(res, req) {
    return res.ok("par");
  },
};

Now: OPTIONS /hello/world will respond with hello

GET/POST/DELETE/OPTIONS/PUT/etc /mycontroller/foobar will respond with bar

POST /mycontroller/foobar will respond with par

You can also specify a prefix that'll work the same way as blueprints ones do which will override the 'mycontroller' segment of the url for the exposedMethods section.

TODO:

  • unit tests

Hopefully this will prove useful to someone else, pull requests welcome if you want to tidy it up a bit :)

FAQs

Package last updated on 25 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc