helloworld2.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* a more advanced hello world plugin... it listens for "POST /hello.cs", "POST /hello.as" and "POST /hello" requests... "POST /hello.cs" requests are received and handled by "csworker"... "POST /hello.as" requests are received by "csworker" and forwarded to "asworker" for handling... "POST /hello" requests trigger a misuse error */
  2. {
  3. 'interfaces' :
  4. [{'method':'POST', 'urlm':'^/hello\.[ac]s$'},
  5. {'method':'POST', 'url=':'/hello'}],
  6. 'localcontext' : {'counter':0},
  7. 'csworker' :
  8. function(resp,method,uri,reqData,wcontext)
  9. {
  10. if( uri.match(/\/hello.cs$/) )
  11. {
  12. this.localcontext.counter++;
  13. __postMessage(
  14. {'statusCode':200,
  15. 'changelog':
  16. [{'op':'SYSOUT',
  17. 'text':'Hello #'+this.localcontext.counter+' from csworker #'+__wid}],
  18. 'sequence#':__sequenceNumber(),
  19. 'respIndex':resp});
  20. }
  21. else if( uri.match(/\/hello.as$/) )
  22. _do.chain(
  23. [__wHttpReq(method, uri+'?wid='+wcontext.__aswid, reqData)])(
  24. function()
  25. {
  26. __postMessage(
  27. {'statusCode':200,
  28. 'respIndex':resp});
  29. },
  30. function(err) {__postInternalErrorMsg(resp,err);}
  31. );
  32. else if( uri.match(/\/hello$/) )
  33. __postInternalErrorMsg(resp,'must request /hello.cs or /hello.as');
  34. },
  35. 'asworker' :
  36. function(resp,method,uri,reqData,wcontext)
  37. {
  38. this.localcontext.counter++;
  39. __postMessage(
  40. {'statusCode':200,
  41. 'changelog':
  42. [{'op':'SYSOUT',
  43. 'text':'Hello #'+this.localcontext.counter+' from asworker #'+__wid}],
  44. 'sequence#':__sequenceNumber(),
  45. 'respIndex':resp});
  46. }
  47. }