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

node_simple_router

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node_simple_router

Intelligent router : search for view files in you application, OR define aliases to create your own paths to your views. Futhermore, you can set parameters to be sent to your views

  • 0.1.4
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

Node Simple Router

Documentation

INSTALL :

Go to your server file :

1 - require the module and give it a name : myrouter = require('node_simple_router');
2 - add this after your application setup : app.get('*', router.manageUrl);

Module configuration (config/alias.json):

- active (bool) : if set to false, you url MUST match the path to your view file.
- alias_only (bool) : if set to true, your url segments (separated by "/", must have aliases defined, direct path to file won't work by default !).
- viewFolder : the path to your view folder.
- fileExtension : you view files extension type (ex: '.jade', '.html'). YOU CAN ONLY SET ONE FOR NOW.
- page_not_found : direct path to the view file to render in case of 404 error.
- page_default : direct path to the default view if your url points to your domain name.

======================================================================================= SETTING ALIASES (make your own urls):

* aliasing are name "matches" and you will find them in config/alias.json.

Let's take an example:

Direct path to your view file (from you views main folder) = blog/mapage/index.jade
But you want your user to be redirected to that view with that URL = http://localhost:4000/mysuperblog/mapage/home,
- OR that one : http://localhost:4000/mysuperblog/mapage/mainpage

You will have to create matches (aliases) for the three folders/files guiding to your view file : 
	--> blog
		--> mapage
	 		--> index

The matches in config/alias.json would look like this for the url to works :

"matches":{
    "blog": { 
    	"matchingRoutes":["mysuperblog"]
    }, 
    "index": { 
      	"matchingRoutes":["home","mainpage"]
    },

 }

 ==> This way, http://localhost:4000/mysuperblog/mapage/home WOULD BECOME http://localhost:4000/blog/mapage/index
 IDEM for http://localhost:4000/mysuperblog/mapage/mainpage

 WHAT HAPPENED ?
   1 - "mysuperblog", if it doesn't exists as a folder, will be replaced by its match "blog". 
   2 - THEN, the module will search for "mapage", in the "blog" folder. mapage exists as a folder of the same name, so it does not need an alias !
   3 - FINALLY, "home" or "mainpage" are replaced by their match : "index"
   4 - the module render the view !

======================================================================================= OPTIONAL - SEND PARAMETERS TO YOUR VIEWS (config/routes.json) :

Imagine your want to send a parameter to the view blog/mapage/index.jade when it's called :

1 - go to config/routes.json and add this in the "routes" node :

"blog/mapage/index": { 
  "locals":{
    "title": "Hey, welcome on my blog !",
    "analytics_tracking_code": "{some string}"
  }

  2 - Those parameters will be accessible threw your view with locals.title or locals.analytics_tracking_code

Support / Contributing

You can contact me at julien.bonnin.dev@gmail.com.

Keywords

FAQs

Package last updated on 12 Feb 2014

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