Created
December 9, 2011 19:46
-
-
Save oravecz/1452988 to your computer and use it in GitHub Desktop.
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
| // Set up application | |
| var {Application} = require( 'stick' ); | |
| var log = require('ringo/logging').getLogger(module.id); | |
| var {json} = require( 'ringo/jsgi/response' ); | |
| var {get} = require('ringo/httpclient'); | |
| var app = exports.app = Application(); | |
| app.configure( 'route' ); | |
| /* | |
| // Attempt 1, use module scope | |
| var cache = {}; | |
| // Attempt 2, use global space | |
| global.cache = {}; | |
| var cache = global.cache; | |
| */ | |
| // Attempt 3, use singleton | |
| var cache = module.singleton( 'cache', function() { return {}; } ); | |
| var maps = module.singleton("maps", function() {return {}}); | |
| app.get("/", function(request) { | |
| cache.key = 'Created key in / handler'; | |
| return json(cache); | |
| }); | |
| app.get("/reentry", function(request) { | |
| var result = { | |
| before: cache | |
| } | |
| var url = 'http://localhost:8080/data'; | |
| var response = get( url ).wait(); | |
| log.info( 'Response received, status: {}, content: {}', response.status, response.content ); | |
| result.after = response.content; | |
| return json( result ); | |
| }); | |
| app.get("/data", function(request) { | |
| if (!cache.key) { | |
| cache.key = 'Created key in /data handler'; | |
| } | |
| return json(cache); | |
| }); | |
| // Script to run app from command line | |
| if (require.main === module) { | |
| require("ringo/httpserver").main(module.directory); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment