cozy-proxy
Version:
Cozy Proxy redirects requests properly to the right application of the Cozy platform depending on given path. It also handles authentication to the Cozy for users and devices.
38 lines (37 loc) • 1.08 kB
JavaScript
// Generated by CoffeeScript 1.10.0
module.exports = function(req, res, next) {
var buf, isNoAuthRoute;
isNoAuthRoute = req.url.indexOf("/routes") !== 0;
isNoAuthRoute = isNoAuthRoute && req.url.indexOf("/login") !== 0;
isNoAuthRoute = isNoAuthRoute && req.url.indexOf("/password") !== 0;
isNoAuthRoute = isNoAuthRoute && req.url.indexOf("/register") !== 0;
isNoAuthRoute = isNoAuthRoute && req.url.indexOf("/device") !== 0;
if (isNoAuthRoute) {
return next();
} else {
req._body = true;
buf = "";
req.setEncoding("utf8");
req.on("data", function(chunk) {
return buf += chunk;
});
return req.on("end", function() {
var err, error;
if (buf.length > 0 && "{" !== buf[0] && "[" !== buf[0]) {
return next(new Error("invalid json"));
}
try {
if (buf.length > 0) {
req.body = JSON.parse(buf);
} else {
req.body = "";
}
return next();
} catch (error) {
err = error;
console.log(err);
return next();
}
});
}
};