app-router
Advanced tools
Comparing version 0.0.8 to 0.0.9
22
index.js
@@ -26,3 +26,3 @@ var fs=require("fs"), | ||
var startRouting= function(routes, expressApp, mainPath){ | ||
var _VARIABLE= routes.VARIABLE || {}; | ||
var _VARIABLE= routes.VARIABLE || routes.variable || {}; | ||
Object.keys(routes).forEach(function(item){ | ||
@@ -137,3 +137,4 @@ if(item.match(/get|post|put|delete|options|resource/i)){ | ||
var textToJSON=function(txtPath, mainPath){ | ||
var text = fs.readFileSync(path.join(mainPath, txtPath), {encoding:"utf8"}); | ||
//var text = fs.readFileSync(path.join(mainPath, txtPath), {encoding:"utf8"}); | ||
var text = loadText(txtPath, mainPath); | ||
var lines = text.split('\n'); | ||
@@ -157,5 +158,9 @@ var strToObj={}; | ||
var loadText= function(filePath, mainPath){ | ||
return fs.readFileSync(path.join(mainPath, filePath), "utf8"); | ||
} | ||
var router=module.exports= function(expressApp){ | ||
return new (function(){ | ||
this.route = function(jsonPath){ | ||
this.route = function(filePath){ | ||
if(!this.path){ | ||
@@ -165,6 +170,8 @@ throw new Error("set working directory first , use setCWD() method"); | ||
var routes; | ||
if(path.extname(routePath) == ".txt"){ | ||
routes =textToJSON(routePath, this.path); | ||
if(path.extname(filePath) == ".txt"){ | ||
routes = textToJSON(filePath, this.path); | ||
}else if(path.extname(filePath) == ".yml"){ | ||
routes = require('js-yaml').load(loadText(filePath, this.path)); | ||
}else{ | ||
routes = require(path.join(this.path, routePath)); | ||
routes = require(path.join(this.path, filePath)); | ||
} | ||
@@ -178,5 +185,4 @@ startRouting(routes, expressApp, this.path); | ||
} | ||
})(); | ||
})(); | ||
} | ||
{ | ||
"name": "app-router", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description":"Routing for expressjs", | ||
"keywords":["express router", "application router", "app-router", "express", "connect", "router", "routing", "json to router", "json-router"], | ||
"keywords":["express router", "application router", "app-router", "yaml-router", "yml-router", "yaml routing", "express", "connect", "router", "routing", "json router", "json-router"], | ||
"bugs":{ | ||
@@ -14,2 +14,5 @@ "url" : "https://github.com/pradeep-mishra/app-router/issues" | ||
"main":"index.js", | ||
"dependencies":{ | ||
"js-yaml":"3.0.1" | ||
}, | ||
"repository" :{ | ||
@@ -16,0 +19,0 @@ "type" : "git", |
@@ -29,3 +29,3 @@ app-router | ||
}, | ||
"GET":{ | ||
"GET":{ | ||
"/user" : ["{cp}:myMiddleWareFunction" , "{cp}:myMethod"], | ||
@@ -98,5 +98,39 @@ "/user/:id" : "{cp}:myClass.myMethod" | ||
app-router also support text routing | ||
<b>Yaml</b> routing in app-router | ||
```javascript | ||
router(app).setCWD(__dirname).route("./routes/route.yml"); | ||
``` | ||
sample <b> route.yml </b> | ||
```yml | ||
VARIABLE: | ||
cp: "./controllers/my_controller" | ||
other_controller: "./controllers/other_controller.js" | ||
GET: | ||
/user: | ||
- "{cp}:myMiddleWareFunction" | ||
- "{cp}:myMethod" | ||
/user/:id: "{cp}:myClass.myMethod" | ||
POST: | ||
/hello: "./controllers/my_controller:createApp" | ||
PUT: | ||
/hello: "{other_controller}:helloPut" | ||
DELETE: | ||
/user: "./controllers/other_controller.js:destroyApp" | ||
RESOURCE: | ||
/res: "{cp}" | ||
/user: "./controllers/user_controller.js" | ||
``` | ||
<b>Text</b> routing in app-router | ||
```javascript | ||
router(app).setCWD(__dirname).route("./routes/route.txt"); | ||
@@ -110,19 +144,19 @@ | ||
VARIABLE cp ./controllers/my_controller | ||
VARIABLE cp ./controllers/my_controller | ||
VARIABLE other_controller ./controllers/other_controller.js | ||
GET /user_controller {cp}:myMiddleWareFunction {cp}:myMethod | ||
GET /user_controller {cp}:myMiddleWareFunction {cp}:myMethod | ||
GET /user/:id ./controllers/other_controller:myClass.myAction | ||
GET /user/:id ./controllers/other_controller:myClass.myAction | ||
POST /hello ./controllers/my_controller:createApp | ||
POST /hello ./controllers/my_controller:createApp | ||
PUT /hello ./controllers/my_controller:createApp | ||
PUT /hello ./controllers/my_controller:createApp | ||
DELETE /user ./controllers/other_controller.js:destroyApp | ||
DELETE /user ./controllers/other_controller.js:destroyApp | ||
RESOURCE /res {cp} | ||
RESOURCE /res {cp} | ||
RESOURCE /user ./controllers/user_controller.js | ||
RESOURCE /user ./controllers/user_controller.js | ||
@@ -129,0 +163,0 @@ |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
11275
232
163
1
+ Addedjs-yaml@3.0.1
+ Addedargparse@0.1.16(transitive)
+ Addedesprima@1.0.4(transitive)
+ Addedjs-yaml@3.0.1(transitive)
+ Addedunderscore@1.7.0(transitive)
+ Addedunderscore.string@2.4.0(transitive)