Skip to content
This repository has been archived by the owner on Jun 16, 2018. It is now read-only.

Commit

Permalink
even simpler localserver
Browse files Browse the repository at this point in the history
  • Loading branch information
rikkertkoppes committed Sep 21, 2016
1 parent 5bb0009 commit 7fe4c72
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 39 deletions.
43 changes: 6 additions & 37 deletions displayserver.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,6 @@
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 1391;

http.createServer(function(request, response) {

var uri = url.parse(request.url).pathname
, filename = path.join(process.cwd(), uri);

fs.exists(filename, function(exists) {
if(!exists) {
response.writeHead(404, {"Content-Type": "text/plain"});
response.write("404 Not Found\n");
response.end();
return;
}

if (fs.statSync(filename).isDirectory()) filename += '/index.html';

fs.readFile(filename, "binary", function(err, file) {
if(err) {
response.writeHead(500, {"Content-Type": "text/plain"});
response.write(err + "\n");
response.end();
return;
}

response.writeHead(200);
response.write(file, "binary");
response.end();
});
});
}).listen(parseInt(port, 10));

console.log("Static file server running at\n => http://localhost:" + port + "/\nCTRL + C to shutdown");
var connect = require('connect');
var serveStatic = require('serve-static');
var port = 1391;
connect().use(serveStatic(__dirname)).listen(port);
console.log('server running on port',port);
console.log('open browser to http://localhost:'+port+'/');
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Display Systems",
"main": "config.js",
"scripts": {
"start": "static -a 0.0.0.0 -p 1391 ."
"start": "node displayserver.js"
},
"repository": {
"type": "git",
Expand All @@ -17,6 +17,7 @@
},
"homepage": "https://github.com/FirstLegoLeague/displaySystem#readme",
"dependencies": {
"node-static": "^0.7.7"
"connect": "^3.5.0",
"serve-static": "^1.11.1"
}
}

0 comments on commit 7fe4c72

Please sign in to comment.