Created
September 19, 2011 16:00
-
-
Save jcolebrand/1226826 to your computer and use it in GitHub Desktop.
Hmmm...
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
var fs = require('fs'); | |
var router = { | |
resource: function(path,methods){ | |
console.log(path); | |
console.log(methods); | |
} | |
}, | |
module = {}; | |
module.exports = function(router){ | |
/* Go get all the routes in the routes directory so we don't have to guess on our own. */ | |
// read all files | |
fs.readdir("routes", function(err,files) { | |
files.forEach(function(val) { | |
// require all non-index.js files. | |
if (val !== "index.js") { | |
require('./routes/' + val).route(router); | |
} | |
}); | |
}); | |
} | |
console.log (module.exports()); |
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
// all naming etc in here is just that, naming. I expect to rename things once I get the idea right. | |
exports.route = function(router){ | |
console.dir(router); | |
router.resource('/', { | |
get : getfs | |
}); | |
}; | |
function getfs(req,res){ | |
res.write('<html><head><title>hello world</title></head><body><h1>this is the new root page</h1><a href="path/">Try this path instead</a></bod | |
y></html>'); | |
res.end(); | |
} |
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
// all naming etc in here is just that, naming. I expect to rename things once I get the idea right. | |
exports.route = function(router){ | |
router.resource('/path/:a123/', { | |
get : getfs | |
}); | |
}; | |
function getfs(req,res){ | |
res.write('<html><head><title>hello world</title></head><body><h1>this is my new page</h1><a href="/">Go home</a></body></html>'); | |
res.end(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
assume for sake of running that the two routes are in a folder called /routes/ next to the main.js (as the code would indicate).
error results anonymized slightly