Skip to content

Commit

Permalink
write our cached index out to index.html.cached, check there first
Browse files Browse the repository at this point in the history
  • Loading branch information
towski committed Jun 4, 2011
1 parent 2194ae8 commit dce7d40
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ mongodb.connect(mongo_config, function(error, db){
});
request.addListener('end', function(){
var parsed = qs.parse(content)
fs.open('index.html', 'w+', 0666, function(err, fd){
fs.open('index.html.cached', 'w+', 0666, function(err, fd){
var buffer = new Buffer("<html><head><script type='text/javascript'>var cached = true;</script>" + parsed.head + "</head><body>"+ parsed.body +"</body></html>")
fs.write(fd, buffer, 0, buffer.length)
})
Expand All @@ -94,11 +94,20 @@ mongodb.connect(mongo_config, function(error, db){
});
} else {
if(!path.match('config.json')){
fs.stat("." + path, function(err, stats){
res.writeHead(200, {'Content-Type': 'text/html'})
fs.readFile("." + path, function(err, data){
res.end(data)
})
fs.stat("." + path + '.cached', function(err, stats){
if(err || authenticated){
fs.stat("." + path, function(err, stats){
res.writeHead(200, {'Content-Type': 'text/html'})
fs.readFile("." + path, function(err, data){
res.end(data)
})
})
} else {
res.writeHead(200, {'Content-Type': 'text/html'})
fs.readFile("." + path + '.cached', function(err, data){
res.end(data)
})
}
})
}
}
Expand Down

0 comments on commit dce7d40

Please sign in to comment.