From d727f6e769ae6f3210a57f32f6c198469efaa9b8 Mon Sep 17 00:00:00 2001 From: natrixaeria Date: Sat, 25 May 2019 22:44:04 +0200 Subject: Run with lighttpd and remove deploy.py --- WebInterface/wasm/asm-paint/Cargo.toml | 1 - WebInterface/wasm/asm-paint/build.sh | 3 - WebInterface/wasm/asm-paint/deploy | 4 -- WebInterface/wasm/asm-paint/deploy.py | 102 ---------------------------- WebInterface/wasm/asm-paint/lighttpd.config | 29 ++++++++ WebInterface/wasm/asm-paint/loader.js | 4 +- WebInterface/wasm/asm-paint/run | 3 + WebInterface/wasm/asm-paint/src/lib.rs | 16 ++--- 8 files changed, 39 insertions(+), 123 deletions(-) delete mode 100755 WebInterface/wasm/asm-paint/build.sh delete mode 100755 WebInterface/wasm/asm-paint/deploy delete mode 100755 WebInterface/wasm/asm-paint/deploy.py create mode 100644 WebInterface/wasm/asm-paint/lighttpd.config create mode 100755 WebInterface/wasm/asm-paint/run (limited to 'WebInterface/wasm') diff --git a/WebInterface/wasm/asm-paint/Cargo.toml b/WebInterface/wasm/asm-paint/Cargo.toml index 5713415..c0a7c68 100644 --- a/WebInterface/wasm/asm-paint/Cargo.toml +++ b/WebInterface/wasm/asm-paint/Cargo.toml @@ -9,4 +9,3 @@ crate-type = ["cdylib"] [dependencies] wasm-bindgen = "0.2" -web-sys = {version="0.3.22", features=["Window", "Document", "HtmlElement", "Node", "Element"]} diff --git a/WebInterface/wasm/asm-paint/build.sh b/WebInterface/wasm/asm-paint/build.sh deleted file mode 100755 index 61c1997..0000000 --- a/WebInterface/wasm/asm-paint/build.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -wasm-pack build --target web diff --git a/WebInterface/wasm/asm-paint/deploy b/WebInterface/wasm/asm-paint/deploy deleted file mode 100755 index 9f7f823..0000000 --- a/WebInterface/wasm/asm-paint/deploy +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -./build.sh -./deploy.py diff --git a/WebInterface/wasm/asm-paint/deploy.py b/WebInterface/wasm/asm-paint/deploy.py deleted file mode 100755 index b64c322..0000000 --- a/WebInterface/wasm/asm-paint/deploy.py +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/env python3 - -from socket import (socket, AF_INET, SOCK_STREAM, IPPROTO_TCP, - SOL_SOCKET, SO_REUSEADDR) -from threading import Thread - -WASM_MIME = 'application/wasm' -JS_MIME = 'application/javascript' -PLAIN_MIME = 'text/plain' -HTML_MIME = 'text/html' - -REQUESTS = { - '/': ('index.html', HTML_MIME), - '/loader.js': ('loader.js', JS_MIME), - '/asm_paint_rs.js': ('pkg/asm_paint_rs.js', JS_MIME), - '/asm_paint_rs_bg.wasm': ('pkg/asm_paint_rs_bg.wasm', WASM_MIME), -} - -PAGE_404 = ''' - -

Request '404 Not Found'

- resource
'{}'
not found
- -''' - -def header_line_to_entry(line): - key, value = line.decode('utf-8').split(': ') - return key, value - - -class Server: - def __init__(self): - self.s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP) - self.s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) - self.threads = [] - - def rec_http(self, client): - headers = b'' - while not headers.endswith(b'\r\n' * 2): - headers += client.recv(1) - headers = headers.split(b'\r\n') - head, headers = headers[0], headers[1:] - method, url, _ = head.split(b' ') - url = url.decode('utf-8') - headers = dict(header_line_to_entry(v) for v in headers if v) - if 'Content-Length' in headers: - client.recv(int(headers['Content-Length'])) - return method, url, headers - - def sen_http(self, client, status='200 OK', payload=b'', mime=PLAIN_MIME): - print('sende...') - client.send((f'HTTP/1.1 {status}\r\n' - f'Content-Length: {len(payload)}\r\n' - f'Content-Type: {mime}\r\n\r\n').encode('utf-8') - + payload) - print('gesendet') - - def run_client(self, client, addr): - while True: - print('wait for receive') - method, url, headers = self.rec_http(client) - print('got receive') - if method == b'GET': - if not url.startswith('/'): - url += '/' - print(f'got request for "{url}"') - if url in REQUESTS: - path, mime = REQUESTS[url] - f = open(path, 'rb') - payload = f.read() - f.close() - self.sen_http(client, '200 OK', payload, mime) - elif url == '/close': - client.close() - self.kill() - exit() - else: - self.sen_http(client, '404 Not Found', - PAGE_404.format(url).encode('utf-8'), - HTML_MIME) - else: - self.sen_http(client, '400 Bad Request', b'only supporting GET') - - def deploy(self, host='localhost', port=8080): - self.s.bind((host, port)) - self.s.listen(1) - while True: - client, addr = self.s.accept() - thread = Thread(target=self.run_client, args=(client,addr)) - self.threads.append(thread) - thread.run() - - def kill(self): - self.s.close() - - -if __name__ == '__main__': - try: - server = Server() - server.deploy() - finally: - server.kill() diff --git a/WebInterface/wasm/asm-paint/lighttpd.config b/WebInterface/wasm/asm-paint/lighttpd.config new file mode 100644 index 0000000..5fae32d --- /dev/null +++ b/WebInterface/wasm/asm-paint/lighttpd.config @@ -0,0 +1,29 @@ +server.http-parseopts = ( + "header-strict" => "enable", + "host-strict" => "enable", + "host-normalize" => "enable", + "url-normalize" => "enable", + "url-normalize-unreserved" => "enable", + "url-normalize-required" => "enable", + "url-ctrls-reject" => "enable", + "url-path-2f-decode" => "enable", + "url-path-dotseg-remove" => "enable", + "url-query-20-plus" => "enable" +) + +server.document-root = "/home/jan/projects/DiscoBot/WebInterface/wasm/asm-paint" +server.port = 8080 +dir-listing.activate = "enable" +index-file.names = ( "index.html" ) +mimetype.assign = ( + ".html" => "text/html", + ".txt" => "text/plain", + ".css" => "text/css", + ".js" => "application/x-javascript", + ".jpg" => "image/jpeg", + ".jpeg" => "image/jpeg", + ".gif" => "image/gif", + ".png" => "image/png", + ".wasm" => "application/wasm", + "" => "application/octet-stream" +) diff --git a/WebInterface/wasm/asm-paint/loader.js b/WebInterface/wasm/asm-paint/loader.js index f1d15ef..4566ee1 100644 --- a/WebInterface/wasm/asm-paint/loader.js +++ b/WebInterface/wasm/asm-paint/loader.js @@ -1,2 +1,2 @@ -import {default as init} from './asm_paint_rs.js' -init('asm_paint_rs_bg.wasm'); +import {default as init} from './pkg/asm_paint_rs.js' +init('./pkg/asm_paint_rs_bg.wasm'); diff --git a/WebInterface/wasm/asm-paint/run b/WebInterface/wasm/asm-paint/run new file mode 100755 index 0000000..61c1997 --- /dev/null +++ b/WebInterface/wasm/asm-paint/run @@ -0,0 +1,3 @@ +#!/bin/sh + +wasm-pack build --target web diff --git a/WebInterface/wasm/asm-paint/src/lib.rs b/WebInterface/wasm/asm-paint/src/lib.rs index 462a89d..b6a5840 100644 --- a/WebInterface/wasm/asm-paint/src/lib.rs +++ b/WebInterface/wasm/asm-paint/src/lib.rs @@ -8,20 +8,14 @@ macro_rules! console_log { extern "C" { #[wasm_bindgen(js_namespace = console)] fn log(s: &str); + + #[wasm_bindgen(js_namespace = document)] + fn write(s: &str); } #[wasm_bindgen(start)] pub fn entry() { - use web_sys; - console_log!("hello {} wasm", 42); - - let window = web_sys::window().unwrap(); - - let document = window.document().unwrap(); - - let body = document.body().unwrap(); - - //body.set_inner_html("

Hello from WASM

"); + console_log!("hello {} wasm", 44); - body.set_inner_html("oho"); + write("gooo"); } -- cgit v1.2.3-54-g00ecf