Created
June 29, 2017 20:03
-
-
Save mezerotm/ed14ab3507579417080889cc2cb2febe to your computer and use it in GitHub Desktop.
Recursively applies routes to restify using [restify-router](https://www.npmjs.com/package/restify-router). Create folders and place index.js at each level. for example `/routes/users/index.js` will appear as `localhost:3000/users/`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function recursivelyApplyRoutes(route){ | |
(function recurse(dir){ | |
let absoluteRoutesPath = process.cwd() + route + (dir? dir:''); | |
fs.readdirSync(absoluteRoutesPath).forEach((file) =>{ | |
let absoluteCurrentFilePath = absoluteRoutesPath + '/' + file; | |
let isDirectory = fs.statSync(absoluteCurrentFilePath).isDirectory(); | |
if(isDirectory) recurse((dir? dir:'') + '/' + file); | |
if(file.indexOf('index.js') !== -1) require(absoluteCurrentFilePath).applyRoutes(server, dir); | |
}); | |
})(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment