- fs.open(json_filename, 'r', function(err, fd) {
- if (err) throw err;
- fs.fstat(fd, function(err, st) {
- if (err) throw err;
- var buffer = new Buffer(1048576);
- fs.read(fd, buffer, 0, 1048576, 0, function(err, bytesRead, buffer) {
+ read_entire_file(json_filename, function(new_json_contents, mtime) {
+ replace_json(new_json_contents, mtime);
+
+ // The HTML can go async, it's not too hopeless if it's out of date by a few milliseconds
+ read_entire_file(html_filename, function(new_html_contents, html_mtime) {
+ var json_headers = {
+ 'X-RGLM': mtime,
+ 'X-RGNV': count_viewers(), // May be slightly out of date.
+ 'Date': (new Date).toUTCString(),
+ };
+ if (MINIMUM_VERSION) {
+ json_headers['X-RGMV'] = MINIMUM_VERSION;
+ }
+ let inline_json = {
+ 'data': JSON.parse(new_json_contents),
+ 'headers': json_headers,
+ };
+ delete inline_json['data']['internal'];
+
+ new_html_contents = new_html_contents.replace(
+ '/*REPLACE:inlinejson*/',
+ 'window.inline_json=' + JSON.stringify(inline_json) + ';');
+ zlib.gzip(new_html_contents, function(err, buffer) {