AdminController.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * Created by benzhan on 15/8/13.
  3. */
  4. var Controller = require('./../framework/Controller.js');
  5. var util = require('util');
  6. var http = require('http');
  7. var querystring = require("querystring");
  8. util.inherits(AdminController, Controller);
  9. var prototype = AdminController.prototype;
  10. /**
  11. * @type {AdminController}
  12. */
  13. var that;
  14. function AdminController() {
  15. Controller.apply(this, arguments);
  16. that = this;
  17. }
  18. /**
  19. * 发送测试环境消息
  20. */
  21. AdminController.prototype.actionSendTestMsg = function(args) {
  22. var host = "test.api.oxzj.net";
  23. _sendMsg(this._req, this._res, host);
  24. }
  25. /**
  26. * 发送正式环境消息
  27. */
  28. AdminController.prototype.actionSendFormalMsg = function(args) {
  29. var host = "sns.api.ouj.com";
  30. _sendMsg(this._req, this._res, host);
  31. }
  32. function _sendMsg(req, res, host) {
  33. var queryStr = querystring.stringify(req.query);
  34. var sreq = http.request({
  35. host: host, // 目标主机
  36. path: '/userMessage/add.do?' + queryStr, // 目标路径
  37. method: req.method // 请求方式
  38. }, function(sres){
  39. sres.pipe(res);
  40. sres.on('end', function(){
  41. });
  42. });
  43. if (/POST|PUT/i.test(req.method)) {
  44. req.pipe(sreq);
  45. } else {
  46. sreq.end();
  47. }
  48. }
  49. module.exports =AdminController;