public
Created — forked from courtneycouch/nodejs-server.js

vertx server test

  • Download Gist
nodejs-server.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
var http = require('http');
var fs = require('fs');
var util = require('util');
 
var fileCache;
var sendFile = function(conn, file) {
conn.writeHead(200, {"Content-Type": "text/html", "Content-Length": file.length});
conn.write(file);
conn.end();
}
http.createServer(function (req, res) {
if (fileCache == undefined) {
fs.readFile("foo.html", function(err, file) {
fileCache = file;
sendFile(res, fileCache);
});
} else {
sendFile(res, fileCache);
}
 
}).listen(8080, 'localhost');
vertx-server.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
load('vertx.js')
var fileCache;
var sendFile = function(req, file) {
req.response.headers["Content-Length"] = file.length();
req.response.headers["Content-Type"] = "text/html";
req.response.end(file);
}
vertx.createHttpServer().requestHandler(function(req) {
if (fileCache == undefined) {
vertx.fileSystem.readFile("httpperf/foo.html" function(err, file) {
fileCache = file;
sendFile(req, fileCache);
});
} else {
sendFile(req, fileCache);
}
 
});
}).listen(8080, 'localhost');

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.