Fix game-of-life example inconsistencies; Fix ternary expression issues in void contexts and variable statements; Simplify HEAP_BASE handling

This commit is contained in:
dcodeIO
2018-04-18 15:12:33 +02:00
parent 4026c087fd
commit 5a2f834c0d
19 changed files with 654 additions and 559 deletions

View File

@ -1,18 +1,32 @@
var open = require('opn');
var http = require('http');
var fs = require('fs');
var http = require("http");
var fs = require("fs");
var open = require("opn");
const PORT = 9080;
const PORT = 9080;
fs.readFile('./game-of-life.html', function (err, html) {
if (err) throw err;
http.createServer(function(request, response) {
response.writeHeader(200, {"Content-Type": "text/html"});
response.write(html);
response.end();
}).listen(PORT);
http.createServer((req, res) => {
var url = req.url;
console.log(req.method + " " + url);
if (/^\/([\w\-_]+(\.\w+)+)?$/i.test(url)) {
if (url === "/") url = "/game-of-life.html";
fs.readFile(__dirname + url, function(err, data) {
if (err) {
res.writeHeader(404);
} else {
res.writeHeader(200, {
"Content-Type":
/\.wasm$/.test(url) ? "application/wasm" :
/\.(json|map)$/.test(url) ? "application/json"
: "text/html"
});
res.write(data);
}
res.end();
});
} else {
res.writeHeader(404);
res.end();
}
}).listen(PORT, () => {
open("http://localhost:9080/");
});
open('http://localhost:9080/game-of-life.html');