This is just a suggestion, you're free to decide if you like it or not.
This creates an option (optional..) called operation with a prototype similar to express (req, res, next) that is called before any operation and enables the developer to inspect the HTTP request and decide if it should continue (next) or respond in another way (using res).
Here's a stupid example:
var printer = new Printer({
name : "My Awesome Printer",
operation : function (req, res, next) {
if (!req.headers.authorization) {
console.log("no guests! you need to auth!");
// it could be DIGEST instead of BASIC
res.writeHead(401, "Not Authorized", {
"WWW-Authenticate": "Basic realm=\"My Awesome Printer\""
});
return res.end();
} else {
console.log("I don't know who you are, I have to base64 decode but at least you typed a username");
}
return next();
}
});
This is just a suggestion, you're free to decide if you like it or not.
This creates an option (optional..) called
operation
with a prototype similar to express (req, res, next
) that is called before any operation and enables the developer to inspect the HTTP request and decide if it should continue (next
) or respond in another way (usingres
).Here's a stupid example: