Skip to content

Instantly share code, notes, and snippets.

@jcolebrand
Created September 19, 2011 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcolebrand/1226826 to your computer and use it in GitHub Desktop.
Save jcolebrand/1226826 to your computer and use it in GitHub Desktop.
Hmmm...
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());
// 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();
}
// 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();
}
@jcolebrand
Copy link
Author

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).

undefined
undefined

/home/cole/quiksilver/routes/route1.js:3
  router.resource('/', {
         ^
TypeError: Cannot call method 'resource' of undefined
    at Object.route (./routes/route1.js:3:10)
    at ./main.js:20:36
    at Array.forEach (native)
    at Object.oncomplete (./main.js:17:11)

error results anonymized slightly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment