app.get("/:alias/:property", function(req, alias, property) { var drummers = { "stevegadd": { birthday: 1945, fullname: "Steve Gadd", drumset: "Yamaha" }, "ringostarr": { birthday: 1940, fullname: "Richard Henry Parkin Starkey Jr.", drumset: "Premier" }, "jeff": { birthday: 1954, fullname: "Jeff Porcaro" } }; // Check if a drummer exists if (drummers[alias]) { if (drummers[alias][property]) { return response.html( "<html><h1>Found a drummer's property:</h1>", "<p>", alias, ".", property, " is: <b>", drummers[alias][property], "</b></p>", "</html>" ); } else { // Return a 404 return response.notFound(alias + "/" + property); } } else { // Return a 404 return response.notFound(alias); } });
exports.app = function(request) { var path = request.pathInfo.slice(1) || "index"; // 1. resolve against actions if (typeof actions[path] === "function") { return actions[path](request); } // 2. resolve against static folder var resource = getResource("./static/" + path); if (resource.exists()) { return response.static(resource); } // 3. return 404 response return response.notFound(request.pathInfo); }
getResponse = function(req) { if (req.pathInfo == '/notfound') { return response.notFound().text("not found"); } else if (req.pathInfo == '/success') { return response.json('success'); } else if (req.pathInfo == '/redirect') { return { status: 302, headers: {Location: '/redirectlocation'}, body: ["Found: " + '/redirectlocation'] }; } else if (req.pathInfo == '/redirectlocation') { return response.html('redirect success'); } };
getResponse = function(req) { return response.notFound(); };
app.get("/api/users/:username/salt", function(request, username) { if (username === "johndoe") { return response.json("salt"); } return response.notFound(); });