~melchizedek6809/WolkenWelten

ref: e910bd82e598d6f560b8899dd1d88fb3ed554cd3 WolkenWelten/tools/wasmserve.py -rwxr-xr-x 1.4 KiB
e910bd82Ben (X13/Arch) Updated contact info 8 months ago
                                                                                
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
import http.server
import socket
import socketserver
import os
import pathlib
import threading
import time
import webbrowser
from subprocess import call

PORT = 4200

class WolkenWeltenHandler(http.server.SimpleHTTPRequestHandler):
    def do_POST(self):
        '''Reads post request body'''
        self.send_response(200)
        self.send_header('Content-type', 'text/html')
        self.end_headers()
        self.wfile.write(bytes("Done", "utf-8"))
        httpd.server_close()
        quit()

def open_browser():
    time.sleep(0.01)
    url = "http://localhost:" + str(PORT) + "/?savegame=test&debuginfo=1"
    webbrowser.open_new(url)

os.chdir(pathlib.Path(__file__).parent.resolve())
call("./buildwasm")
os.chdir("../releases/wasm")

Handler = WolkenWeltenHandler
Handler.extensions_map={
	'.manifest': 'text/cache-manifest',
	'.html':     'text/html',
	'.png':      'image/png',
	'.jpg':      'image/jpg',
	'.svg':      'image/svg+xml',
	'.css':      'text/css',
	'.js':       'application/x-javascript',
	'.wasm':     'application/wasm',
	'':          'application/octet-stream'}


socketserver.TCPServer.allow_reuse_address = True
httpd = socketserver.TCPServer(("", PORT), Handler)
httpd.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

print("serving at port http://localhost:" + str(PORT))
threading.Thread(target=open_browser).start()
try:
    httpd.serve_forever()
except KeyboardInterrupt:
    httpd.server_close()