Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@colucom/osseus-router

Package Overview
Dependencies
Maintainers
4
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@colucom/osseus-router

Osseus Router

  • 0.4.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
Maintainers
4
Weekly downloads
 
Created
Source

JavaScript Style Guide

Osseus Router

JSON Routes (for osseus) based osseus module to work with osseus-server

Install

$ npm install @colucom/osseus-router

Usage

Configuration

Mandatory:

  • OSSEUS_ROUTER_DEPENDENCIES

Optional:

  • OSSEUS_ROUTER_ROUTES_PATH
    • the path to your routes folder
    • default is ./routes
  • OSSEUS_ROUTER_CONTROLLERS_PATH
    • the path to your controllers folder
    • default is ./contollers
  • OSSEUS_ROUTER_POLICY_PATH
    • the path to your policy (middlewares) folder
    • default is ./policy
  • OSSEUS_ROUTER_URL_PREFIX
    • global prefix path for all routes
  • OSSEUS_ROUTER_CONTROLLER_NAME_NO_UPPERCASE
    • set to true in order for contorller names not to begin with uppercase (which is the default)
Example

/routes/examples.json:

{
  "/example": {
    "GET": {
      "policy": "global:firstPolicy",
      "route": "exampleGET"
    },
    "POST": {
      "policy": [
        "global:firstPolicy",
        "global:secondPolicy"
      ],
      "route": "./controllers/AnotherController:examplePOST"
    }
  }
}

Note

By default all routes in /routes/example.json are assumed to be in /controllers/ExamplesController.js but in case you want to use a route from another controller need to specify its location

/policy/global.js:

module.exports = (osseus) => {
  return {
    firstPolicy: (req, res, next) => {
      req.policies = req.policies || []
      req.policies.push('firstPolicy')
      next()
    },
    secondPolicy: (req, res, next) => {
      req.policies = req.policies || []
      req.policies.push('secondPolicy')
      next()
    }
  }
}

/controllers/ExamplesController.js:

module.exports = (osseus) => {
  return {
    examplePOST: (req, res, next) => {
      res.send({called: 'examplePOST', policies: req.policies})
    }
  }
}

/controllers/AnotherController.js:

module.exports = (osseus) => {
  return {
    examplePOST: (req, res, next) => {
      res.send({called: 'examplePOST', policies: req.policies})
    }
  }
}

Running:

$ node index.js --OSSEUS_SERVER_PORT 8080

Will start your application and listen on 8080.

Now, let's send some test requests and see what we get:

$ curl 0:3000/example

will result in:

$ {"called":"exampleGET","policies":["firstPolicy"]}

and:

$ curl -XPOST 0:3000/example

will result in:

$ {"called":"examplePOST","policies":["firstPolicy","secondPolicy"]}

More detailed examples can be found here

Contributing

Please see contributing guidelines.

License

Code released under the MIT License.

FAQs

Package last updated on 24 Oct 2018

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