Browse files

Got the server reading from fake origin, writing to a cache file, and…

… sending the cached response back
  • Loading branch information...
1 parent e320ae9 commit 048931b2449bcca8a653eaf402c2b1e997f8250f Zachary Parmley committed Aug 13, 2012
Showing with 12 additions and 13 deletions.
  1. +12 −13 BillBill.js
View
25 BillBill.js
@@ -1,3 +1,4 @@
+var async = require('async')
var fs = require('fs')
var filed = require('filed')
var http = require('http')
@@ -22,19 +23,17 @@ http.createServer(function(req, resp) {
} else {
// Cache miss
- // Currently a server on 2020 is waitig 3 seconds and sending a simple response, for dev
- var originReq = request('http://localhost:2020')
- var filedFile = filed(cacheFile)
-
- console.log(originReq)
-
- originReq.on('close', function() {
- filedFile.pipe(resp)
- })
-
- originReq.pipe(filedFile)
- // filed(cacheFile).pipe(resp)
- // .pipe(resp)
+ // I'd hoped to do something a little different, namely pipe the request to multiple destinations (file and response) but alas, it is beyond me at the moment
+ // I'm a little worried about a race condition with this setup, where the request is complete but the file write is not, so an incomplete file is read and set back - not sure yet if this is a problem or best sollution
+
+ // DEV Currently a server on 2020 is waitig 3 seconds and sending a simple response, for dev
+ // Request from the origin and pipe it to the cache file
+ request('http://localhost:2020', function(e, r, b) {
+ if (!e) {
+ // If no error, pipe the cached file back to the response object when complete
+ filed(cacheFile).pipe(resp)
+ }
+ }).pipe(filed(cacheFile))
}
})

0 comments on commit 048931b

Please sign in to comment.