project structure cleanup

This commit is contained in:
Thilo Behnke
2022-06-11 18:26:33 +02:00
parent 938e7e5311
commit 7e430e3000
32 changed files with 119 additions and 41 deletions

View File

@@ -1,47 +1,8 @@
[package]
name = "rust-wasm"
name = "rust-wasm-pong"
version = "0.1.0"
authors = ["Thilo Behnke <thilo.behnke@gmx.net>"]
edition = "2018"
[workspace]
members = ["pong", "server"]
[lib]
crate-type = ["cdylib", "rlib"]
[dependencies.web-sys]
version = "0.3"
features = [
"console",
]
[features]
default = ["console_error_panic_hook"]
[dependencies]
wasm-bindgen = {version = "0.2.63", features = ["serde-serialize"]}
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0.79" }
pong = { path = "pong", version = "0.1.0" }
# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
console_error_panic_hook = { version = "0.1.6", optional = true }
# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
# compared to the default allocator's ~10K. It is slower than the default
# allocator, however.
#
# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now.
wee_alloc = { version = "0.4.5", optional = true }
[dev-dependencies]
wasm-bindgen-test = "0.3.13"
rstest = "0.12.0"
[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"
members = ["client", "pong", "server"]

44
client/Cargo.toml Normal file
View File

@@ -0,0 +1,44 @@
[package]
name = "rust-wasm"
version = "0.1.0"
authors = ["Thilo Behnke <thilo.behnke@gmx.net>"]
edition = "2018"
[lib]
crate-type = ["cdylib", "rlib"]
[dependencies.web-sys]
version = "0.3"
features = [
"console",
]
[features]
default = ["console_error_panic_hook"]
[dependencies]
wasm-bindgen = {version = "0.2.63", features = ["serde-serialize"]}
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0.79" }
pong = { path = "../pong", version = "0.1.0" }
# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
console_error_panic_hook = { version = "0.1.6", optional = true }
# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
# compared to the default allocator's ~10K. It is slower than the default
# allocator, however.
#
# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now.
wee_alloc = { version = "0.4.5", optional = true }
[dev-dependencies]
wasm-bindgen-test = "0.3.13"
rstest = "0.12.0"
[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"

28
client/nginx/default.conf Normal file
View File

@@ -0,0 +1,28 @@
server {
listen 80;
listen [::]:80;
location / {
return 301 /pong/web;
}
location /pong/web/ {
root /usr/share/pong/;
try_files $uri$args $uri$args/ /index.html;
}
location /pong/api/ {
proxy_pass http://api_server/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}

45
client/nginx/nginx.conf Normal file
View File

@@ -0,0 +1,45 @@
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream api_server {
server localhost:4000;
}
upstream web_client {
server localhost:8080;
}
}

0
src/main.rs Normal file
View File