Skip to content

Instantly share code, notes, and snippets.

@gotomypc
Forked from courtneycouch/nodejs-server.js
Created September 1, 2014 05:24
Show Gist options
  • Save gotomypc/a183b1558abc0c439ee4 to your computer and use it in GitHub Desktop.
Save gotomypc/a183b1558abc0c439ee4 to your computer and use it in GitHub Desktop.
ar 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');
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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment