npm package: @synapse/minroute
Description: A mini router from the min project
Author: synapse
Latest version: 1.0.5

This is a component of the overall project called minproject, a suite of minimalist web components designed to get web projects up and running fast without ugly callback code and bloated middlewarez. Relies heavily on the node.js API, this is the heart of minproject.

What is it? - minroute is a minimalist static router that's easy to build upon and customise for your project. It builds everything for you in your project, all your routing paths and directories. minroute can be used to
build templates very eaily and quickly. Simply delete the project_settings.json from the config folder, edit the theme folder name in minroutes lib and it will build a new routing file that routes to your new template. The project_settings.json has an entry 'routesFile' which you can change at any time to create a new site quickly.

minroute does not DEPEND on mininit but it is designed to be used with mininit.

1) mininit generates a project globals object, config dir and config file in the format of: 

    setup = {
    { project_settings:
        [ { osType: 'win32',
            pathType: '\\',
            rootDir: 'C:\\Users\\jsmur\\Documents\\Programs\\NodeJS\\NODE.APPS\\minproject',
            configDir: 'config',
            configFile: 'project-settings.json' } ],
     db_settings: [ { host: 'local', port: 200, db: 'test' } ] }


2) minroute will accept the above object into the constructor function. It will then check for an entry under the key 'project_settings' called 'routesFile', if no entry is found the entry will be added to the passed object in memory and then it will be saved to disk. It's this that enables minroute to work without mininit, no dependencies.

Minroute will use the rootDir property, configDir and configFile properties in the passed object to save the file to disk, so it is advisable to ensure the directory specified in configDir exists before passing this to minroute though in my testing configDir and configFile do not need to exist, they will be written but it depends on your OS permissions.

3) If minroute is used with mininit you don't need to do anything, your project will be initialised automatically. 
[USAGE]

Usage is like the following:

var mininit = require('@synapse/mininit');
var minroute = require('@synapse/minroute');
var http = require('http');

mininit.initConfig({host:'localhost', port:27017, db:'dbname'});

minroute.initRoutes(mininit.getConfig());

var proxy = http.createServer(function(req,res) {

/* Use the router here */

    if(typeof minroute.MatchRequest(req) === 'object' ) {
    
        minroute.fileServe( minroute.MatchRequest(req), req, res );
        
     else {
     
        minroute.notFound(res);
     }




});

proxy.listen(8000);

3 a) Edit your routes.json file to the resources you want to serve and copy your assets (html, css) to the folders built for you and that's all you need to do for a working web server.

3 b) Want a new template? simply delete the project_settings.json from config directory, navigate to router.js under minroute/lib, edit the SERVE_ROOT_DIR_NAME variable to something like 'myTemplateTwo' and re run your project.

4) minroute.getRoutes() will return an object that holds the routing information as it's own property (not a prototype) and the config dir will have a routes.json. Additionally, mininit.getConfig() returns the config object which will have a new property called 'requested_paths' generated by minroute which will have path names for all public folders to be used for the router.

5) All folders and filenames produced by mininit and minroute can be edited safely if you so desire, as they are specified as constants at the top of their core lib files.

6) Example usage of minroute without mininit: 

var minroute = require('@synapse/minroute');

var setup = {};

setup = {
    
project_settings:
   [ { osType: 'win32',
       pathType: '\\',
       rootDir: 'C:\\Users\\jsmur\\Documents\\Programs\\NodeJS\\NODE.APPS\\testModule',
       configDir: 'config',
       configFile: 'project-settings.json' } ],
db_settings:
   [ { host: 'local',
       port: 200,
       db: 'test' } ] };
  
  
minroute.initRoutes(setup);

console.log(minroute.getRoutes());