updated schedule api; updated index routing; + routing based on Accept header;
This commit is contained in:
1 parent
6af90258c9
commit
a694abb3e5
6 files changed
+148
-29
No files matched your search
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Created by tmshv on 01/03/15.
|
||||
*/
|
||||
|
||||
var path = require("path");
|
||||
var fs = require("mz/fs");
|
||||
|
||||
function accepts(routes, def) {
|
||||
return function *() {
|
||||
var req = this.request;
|
||||
var types = Object.keys(routes)
|
||||
.filter(function (type) {
|
||||
return req.accepts(type);
|
||||
});
|
||||
|
||||
if (types.length) {
|
||||
var type = types[0];
|
||||
yield routes[type].apply(this, arguments);
|
||||
} else if(def){
|
||||
yield def;
|
||||
}else{
|
||||
this.status = 406;
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function index(filename) {
|
||||
if (!filename){
|
||||
filename = path.join(__dirname, "../templates/index.html");
|
||||
}
|
||||
|
||||
return function *() {
|
||||
this.type = "text/html";
|
||||
this.body = fs.createReadStream(filename);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
index: index,
|
||||
accepts: accepts
|
||||
};
|
||||
Reference in new issue
Block a user