Socket
Socket
Sign inDemoInstall

app-router

Package Overview
Dependencies
0
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.6 to 0.0.7

52

index.js

@@ -26,6 +26,6 @@ var fs=require("fs"),

var startRouting= function(routes, expressApp, mainPath){
var _GLOBAL= routes.GLOBAL || {};
var _VARIABLE= routes.VARIABLE || {};
Object.keys(routes).forEach(function(item){
if(item.match(/get|post|put|delete|options|resource/i)){
routeMethod(routes[item], item, _GLOBAL, expressApp, mainPath);
routeMethod(routes[item], item, _VARIABLE, expressApp, mainPath);
}

@@ -35,24 +35,24 @@ });

var routeMethod = function(routes, methodType, _GLOBAL, expressApp, mainPath){
var routeMethod = function(routes, methodType, _VARIABLE, expressApp, mainPath){
if(util.isArray(routes)){
return routes.forEach(function(thisRoute){
processRoute(thisRoute, methodType, _GLOBAL, expressApp, mainPath);
processRoute(thisRoute, methodType, _VARIABLE, expressApp, mainPath);
});
}
processRoute(routes, methodType, _GLOBAL, expressApp, mainPath);
processRoute(routes, methodType, _VARIABLE, expressApp, mainPath);
}
var processRoute = function(routes, methodType, _GLOBAL, expressApp, mainPath){
var processRoute = function(routes, methodType, _VARIABLE, expressApp, mainPath){
Object.keys(routes).forEach(function(item){
var controller =util.isArray(routes[item])?
interPolateArray(routes[item], _GLOBAL):
interPolate(routes[item], _GLOBAL);
routeThis(item, methodType, controller, expressApp, _GLOBAL, mainPath);
interPolateArray(routes[item], _VARIABLE):
interPolate(routes[item], _VARIABLE);
routeThis(item, methodType, controller, expressApp, _VARIABLE, mainPath);
});
}
var routeThis = function(route, methodType, controllers, expressApp, _GLOBAL, mainPath){
var routeThis = function(route, methodType, controllers, expressApp, _VARIABLE, mainPath){
methodType=methodType.toLowerCase();
if(methodType=="resource"){
return resourceThis(route, controllers, expressApp, _GLOBAL, mainPath);
return resourceThis(route, controllers, expressApp, _VARIABLE, mainPath);
}

@@ -88,3 +88,3 @@ var actions;

var resourceThis= function(route, controller, expressApp, _GLOBAL, mainPath){
var resourceThis= function(route, controller, expressApp, _VARIABLE, mainPath){
var resourcing={

@@ -138,2 +138,22 @@ index:{

var textToJSON=function(txtPath, mainPath){
var text = fs.readFileSync(path.join(mainPath, txtPath), {encoding:"utf8"});
var lines = text.split('\n');
var strToObj={};
lines.forEach(function(line, num){
var cmds =line.split(/[\s\t]+/);
if(cmds.length < 3){
if(cmds.length > 1){
throw new Error("Invalid Routing line number:" + (num+1) + " " +line);
}
return false;
}
var verb = cmds.shift().trim().toUpperCase(),
route = cmds.shift().trim();
strToObj[verb] = strToObj[verb] || {};
strToObj[verb][route]= (cmds.length > 1 ? cmds : cmds[0]);
});
return strToObj;
}
var router=module.exports= function(expressApp){

@@ -145,4 +165,10 @@ return new (function(){

}
var routes = require(path.join(this.path, jsonPath));
var routes;
if(path.extname(routePath) == ".txt"){
routes =textToJSON(routePath, this.path);
}else{
routes = require(path.join(this.path, routePath));
}
startRouting(routes, expressApp, this.path);
},

@@ -149,0 +175,0 @@ this.setCWD = function(mainPath){

{
"name": "app-router",
"version": "0.0.6",
"version": "0.0.7",
"description":"Routing for expressjs",

@@ -5,0 +5,0 @@ "keywords":["express router", "application router", "app-router", "express", "connect", "router", "routing", "json to router", "json-router"],

@@ -25,6 +25,6 @@ app-router

{
"GLOBAL":{
"VARIABLE":{
"cp":"./controllers/my_controller",
"other_controller":"./controllers/other_controller.js"
},
},
"GET":{

@@ -60,3 +60,4 @@ "/user" : ["{cp}:myMiddleWareFunction" , "{cp}:myMethod"],

Method Route Action (in controller ./controllers/user_controller.js)
Method Route Action (in controller ./controllers/user_controller.js)
GET /user -> index

@@ -98,1 +99,33 @@ GET /user.:format -> index

app-router also support text routing
```javascript
router(app).setCWD(__dirname).route("./routes/route.txt");
```
sample <b> route.txt </b>
```javascript
VARIABLE cp ./controllers/my_controller
VARIABLE other_controller ./controllers/other_controller.js
GET /user_controller {cp}:myMiddleWareFunction {cp}:myMethod
GET /user/:id ./controllers/other_controller.js
POST /hello ./controllers/my_controller:createApp
PUT /hello ./controllers/my_controller:createApp
DELETE /user ./controllers/other_controller.js:destroyApp
RESOURCE /res {cp}
RESOURCE /user ./controllers/user_controller.js
```
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc