forked from davidbierbauer/simplesite
-
Notifications
You must be signed in to change notification settings - Fork 1
/
routing.js
32 lines (26 loc) · 860 Bytes
/
routing.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* @fileOverview Custom routing middleware
*/
var response = require("ringo/jsgi/response");
/**
* Middleware for HTTP method based local request routing.
* @param {Function} next the wrapped middleware chain
* @param {Object} app the Stick Application object
* @returns {Function} a JSGI middleware function
*/
exports.middleware = function route(next, app) {
var handler = function() {
return require("ringo/jsgi/repsonse").bad();
};
app.get = function(newHandler) {
handler = newHandler;
};
return function route(req) {
var method = req.method;
// Jetty strips the content for HEAD requests
if (method === "GET" || method === "HEAD") {
return handler.apply(null, [req, req.pathInfo]);
}
return response.text("Not Implemented.").setStatus(501);
};
};