-
Notifications
You must be signed in to change notification settings - Fork 19
/
server.js
33 lines (24 loc) · 822 Bytes
/
server.js
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
29
30
31
32
"use strict"
const http = require("http")
const fs = require("fs")
const url = require("url")
const PORT = 1337
http.createServer((request, response) => {
let path = url.parse(request.url).pathname
let data
path = (path=="/"?"/examples/index.html":path).replace(/%20/g, " ")
console.log(path)
switch (true) {
case path.endsWith("/NetWASM.wasm"):
try {
console.log("Returning the wasm file", __dirname+"/dist/NetWASM.wasm")
data = fs.readFileSync(__dirname+"/dist/NetWASM.wasm")
} catch (e) {}
break
default:
try {
data = fs.readFileSync(__dirname+path)
} catch (e) {}
}
response.end(data)
}).listen(PORT, () => console.log(`Server Listening on port: ${PORT}`))