Skip to content

Commit

Permalink
chore: Apply snowflake changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Krems committed Mar 23, 2016
1 parent 52fc9ac commit a3c7aa7
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 52 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ node_js:
before_install:
- npm install -g npm@latest-2
before_deploy:
- 'git config --global user.email "jan.krems@groupon.com"'
- 'git config --global user.name "Jan Krems"'
- 'git config --global user.email "opensource@groupon.com"'
- 'git config --global user.name "Groupon"'
deploy:
provider: script
script: ./node_modules/.bin/nlm release
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2016, Jan Krems
Copyright (c) 2016, Groupon, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
},
"scripts": {
"start": "node server.js",
"pretest": "eslint lib test",
"test": "mocha",
"test": "eslint server.js",
"posttest": "nlm verify"
},
"nlm": {
Expand All @@ -31,15 +30,13 @@
"node-static": "~0.7.7"
},
"devDependencies": {
"assertive": "^2.0.0",
"eslint": "^1.0.0",
"eslint-config-groupon": "^2.0.0",
"mocha": "^2.0.0",
"nlm": "^2.0.0"
},
"author": {
"name": "Jan Krems",
"email": "jan.krems@groupon.com"
"name": "Groupon",
"email": "opensource@groupon.com"
},
"files": [
"*.js",
Expand Down
53 changes: 29 additions & 24 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ function echo(request, response) {
method: request.method,
url: request.url,
body: '',
headers: request.headers
headers: request.headers,
};

request.on('data', function(buffer) {
request.on('data', function appendData(buffer) {
data.body += buffer.toString();
});

request.on('end', function() {
request.on('end', function sendResponse() {
var body = JSON.stringify(data, null, 2);
response.setHeader('Content-Type', 'application/json');
response.end(body);
Expand All @@ -36,50 +36,55 @@ function crash(response) {
response.socket.destroy();
}

function serveFromDisk(file, request, response) {
var listener = request.addListener('end', function serveFile() {
file.serve(request, response);
});
listener.resume();
}

function createServer() {
var file = new StaticServer(__dirname + '/public');

return http.createServer(function(request, response) {
var parsedUrl = parseUrl(request.url)
return http.createServer(function handleRequest(request, response) {
var parsedUrl = parseUrl(request.url);
switch (parsedUrl.pathname) {
case '/echo':
return echo(request, response);
case '/echo':
return echo(request, response);

case '/error':
return error(response);
case '/error':
return error(response);

case '/crash':
return crash(response);
case '/crash':
return crash(response);

case '/blackhole':
return;
}
case '/blackhole':
return undefined;

var listener = request.addListener('end', function() {
file.serve(request, response);
});
listener.resume();
default:
return serveFromDisk(file, request, response);
}
});
}

var testApp = module.exports = {
listen: function(port, callback) {
listen: function listen(port, callback) {
this.server = createServer();
this.server.listen(port, callback);
},

kill: function(callback) {
kill: function kill(callback) {
this.server.close(callback);
this.server = null;
}
},
};

if (module === require.main) {
if (process.env.never_listen) {
console.log('Refusing to listen')
setTimeout(function() {}, 100000);
console.log('Refusing to listen');
setTimeout(function noop() {}, 100000);
} else {
testApp.listen(process.env.PORT || 4003, function() {
testApp.listen(process.env.PORT || 4003, function onListen() {
console.log('Listening on port %j', this.address().port);
});
}
Expand Down
8 changes: 0 additions & 8 deletions test/.eslintrc

This file was deleted.

1 change: 0 additions & 1 deletion test/mocha.opts

This file was deleted.

10 changes: 0 additions & 10 deletions test/testium-example-app.test.js

This file was deleted.

0 comments on commit a3c7aa7

Please sign in to comment.