Skip to content

Commit

Permalink
bug fix: can not find the path: undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoqiang-zhao committed Sep 20, 2017
1 parent 9e505b4 commit 3d12555
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';

/**
* Module dependencies.
* @file 功能文件
* @author longze
*/

'use strict';

const assert = require('assert');
const fs = require('fs');
const resolve = require('path').resolve;
Expand Down Expand Up @@ -34,25 +35,22 @@ function getData(path, req, res, next) {
console.log(e);
}
}
else {
body = 'can not find the path: ' + absolutePath;
}

return body;
}

/**
* auto path router from `root`.
*
* @param {String} root
* @param {string} rootPath mock文件夹根路径
* @return {Function}
* @api public
*/
function mock(rootPath) {

assert(rootPath, 'root path directory is required to serve files');
rootPath = resolve(rootPath);

return function (req, res, next) {
let pathname = url.parse(req.url).pathname;
let path = rootPath + '/' + req.method + pathname;
Expand All @@ -64,4 +62,4 @@ function mock(rootPath) {
next();
}
};
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "express-auto-path-router",
"version": "1.3.0",
"version": "1.3.1",
"description": "Auto path router serving middleware for express",
"scripts": {
"test": "node ./node_modules/.bin/mocha",
Expand Down

0 comments on commit 3d12555

Please sign in to comment.