unit22

Untitled

Feb 17th, 2012
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. (function () {
  2. var express = require("express"),
  3. fluid = require("infusion"),
  4. gpii = fluid.registerNamespace("gpii");
  5. fluid.require("../../../../../dataSource.js");
  6.  
  7. process.on("uncaughtException", function (err) {
  8. console.log("Uncaught Exception: " + err);
  9. process.exit(1);
  10. });
  11.  
  12. process.on("SIGTERM", function () {
  13. process.exit(0);
  14. });
  15.  
  16. var getBaseDir = function () {
  17. return __dirname;
  18. };
  19.  
  20. var buildPath = function (pathSeg) {
  21. return path.join(getBaseDir(), pathSeg);
  22. };
  23.  
  24. var preferencesServer = express.createServer(
  25. // In case we want to support https
  26. // {
  27. // key: fs.readFileSync('path/to/key.pem'),
  28. // cert: fs.readFileSync('path/to/cert.pem')
  29. // }
  30. );
  31.  
  32. preferencesServer.configure(function () {
  33. preferencesServer.use(express.bodyParser());
  34. });
  35.  
  36. preferencesServer.configure("production", function () {
  37. // Set production options.
  38. fluid.staticEnvironment.production = fluid.typeTag("gpii.production");
  39. preferencesServer.set("userDataSource", gpii.dataSource({
  40. host: "0.0.0.0",
  41. port: 5984,
  42. url: "%db/user/%token",
  43. termMap: {
  44. token: "%token"
  45. }
  46. }));
  47. });
  48.  
  49. preferencesServer.configure("development", function () {
  50. // Set development options.
  51. fluid.staticEnvironment.production = fluid.typeTag("gpii.development");
  52. preferencesServer.set("userDataSource", gpii.dataSource({
  53. url: "%db/test/data/%token.json",
  54. termMap: {
  55. token: "%token"
  56. }
  57. }));
  58. });
  59.  
  60. preferencesServer.all("/user/:id", function (req, res, next) {
  61. // params available: id
  62. req.id = req.params.id;
  63. next();
  64. });
  65.  
  66. preferencesServer.get("/user/:id", function (req, res) {
  67. preferencesServer.settings.userDataSource.get({
  68. token: req.id
  69. }, function (resp) {
  70. res.send(resp, 200);
  71. }, function (message, error) {
  72. console.log(message);
  73. });
  74. });
  75.  
  76. preferencesServer.listen(8080);
  77.  
  78. })();
Advertisement
Add Comment
Please, Sign In to add comment