Created
January 2, 2014 22:37
-
-
Save janewilkin/8228461 to your computer and use it in GitHub Desktop.
Trying to access the result object to write my response to the client.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| I have a server that uses this director setup: | |
| function posts() { | |
| var type = 'posts'; | |
| analytics(type,this); | |
| } | |
| function sections() { | |
| var type = 'sections'; | |
| analytics(type,this); | |
| } | |
| function tags() { | |
| var type = 'tags'; | |
| analytics(type,this); | |
| } | |
| function authors() { | |
| var type = 'authors'; | |
| analytics(type,this); | |
| } | |
| function staticServe() { | |
| console.log('staticServe in'); | |
| file.serve(this.req, this.res); | |
| console.log('staticServe out'); | |
| } | |
| // define a routing table. | |
| var router = new director.http.Router({ | |
| '/v2': { | |
| '/analytics': { | |
| '/posts': { | |
| get: posts | |
| }, | |
| '/sections': { | |
| get: sections | |
| }, | |
| '/tags': { | |
| get: tags | |
| }, | |
| '/authors': { | |
| get: authors | |
| } | |
| } | |
| } | |
| }); | |
| But now I want to try using URL matching: | |
| https://github.com/flatiron/director#url-matching | |
| so I've got this configuration... but where did "this" go? will it still get passed to my function? Doesnt seem to get passed: | |
| // define a routing table. | |
| var router = new director.http.Router({ | |
| '/case':{ | |
| '/:id': { | |
| get: getCaseResults | |
| } | |
| } | |
| }); | |
| and this function, but director is "undefined", while caseId has the value that i pass in with the following curl request | |
| function getCaseResults(caseId,director) { | |
| console.log('getCaseResults ' + caseId); | |
| console.log(Array.prototype.slice.call(arguments)); | |
| var results = history.getResults(caseId); | |
| director.res.writeHead(200, {'Content-Type': 'application/json'}); | |
| director.res.end(results); | |
| } | |
| $ curl -X GET 'http://localhost:8080/case/1' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment