Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 28 lines (25 sloc) 0.857 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
"use strict";
var ez = require('ez-streams');
var url = require('url');
var qs = require('querystring');

var begPage = '<html><head><title>My Search</title></head></body>' + //
'<form action="/">Search: ' + //
'<input name="q" value="{q}"/>' + //
'<input type="submit"/>' + //
'</form><hr/>';
var endPage = '<hr/>generated in {ms}ms</body></html>';

ez.devices.http.server(function(request, response, _) {
var query = qs.parse(url.parse(request.url).query),
t0 = new Date();
response.writeHead(200, {
'Content-Type': 'text/html; charset=utf8'
});
response.write(_, begPage.replace('{q}', query.q || ''));
response.write(_, search(_, query.q));
response.write(_, endPage.replace('{ms}', new Date() - t0));
response.end();
}).listen(_, 1337);
console.log('Server running at http://127.0.0.1:1337/');

function search(_, q) {
return "NIY: " + q;
}
Something went wrong with that request. Please try again.