From fe31184f1fd9fa8d32a4758bdfcc6bc96b27e75f Mon Sep 17 00:00:00 2001 From: mycognosist Date: Mon, 11 May 2020 12:16:18 +0100 Subject: [PATCH] update section on webapp and add placeholder for peach-patterns --- src/SUMMARY.md | 1 + src/software/pattern_library.md | 1 + src/software/web_interface.md | 96 ++++++++++++++++++++++++++++++++- 3 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 src/software/pattern_library.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index e73b236..501f93f 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -15,6 +15,7 @@ - [peach-oled](./software/microservices/peach-oled.md) - [peach-stats](./software/microservices/peach-stats.md) - [Web Interface](./software/web_interface.md) + - [Pattern Library](./software/pattern_library.md) - [Configuration](./software/configuration.md) - [Contributor's Guide](./contributors_guide.md) - [Licensing](./licensing.md) diff --git a/src/software/pattern_library.md b/src/software/pattern_library.md new file mode 100644 index 0000000..6c85158 --- /dev/null +++ b/src/software/pattern_library.md @@ -0,0 +1 @@ +# peach-patterns diff --git a/src/software/web_interface.md b/src/software/web_interface.md index 326dd66..061b298 100644 --- a/src/software/web_interface.md +++ b/src/software/web_interface.md @@ -2,6 +2,98 @@ [peach-web](https://github.com/peachcloud/peach-web) provides a web interface for monitoring and interacting with the PeachCloud device. This allows administration of the single-board computer (ie. Raspberry Pi) running PeachCloud, as well as the ssb-server and related plugins. -**Stack** +### Design + +`peach-web` is written primarily in Rust and presents a web interface for interacting with the device. The stack currently consists of [Rocket](https://rocket.rs/) (Rust web framework), [Tera](https://tera.netlify.com/docs/installation/) (Rust template engine inspired by Jinja2 and the Django template language), HTML, CSS and JavaScript. Additional functionality is provided by JSON-RPC clients for the `peach-network` and `peach-stats` microservices. + +HTML is rendered server-side. Request handlers call JSON-RPC microservices and serve HTML and assets. A JSON API is exposed for remote calls and dynamic client-side content updates via vanilla JavaScript following [unobstructive design principles](https://www.w3.org/wiki/The_principles_of_unobtrusive_JavaScript). A basic Websockets server is included, though is not currently utilised. Each Tera template is passed a context object. In the case of Rust, this object is a `struct` and must implement `Serialize`. The fields of the context object are available in the context of the template to be rendered. + +### Directory Tree + +``` +. +├── Cargo.lock +├── Cargo.toml +├── docs +│   ├── api_docs.md +│   ├── FEATURES.md +│   ├── js_docs.md +│   └── RESOURCES.md +├── .gitignore +├── README.md +├── Rocket.toml +├── src +│   ├── device.rs +│   ├── error.rs +│   ├── lib.rs +│   ├── main.rs +│   ├── network.rs +│   ├── stats.rs +│   ├── structs.rs +│   ├── tests.rs +│   └── ws.rs +├── static +│   ├── css +│   │   ├── peachcloud.css +│   │   └── _variables.css +│   ├── favicon.ico +│   ├── icons +│   ├── js +│   │   ├── network_card.js +│   │   ├── shutdown_menu.js +│   └── templates +│   ├── base.html.tera +│   ├── device.html.tera +│   ├── index.html.tera +│   ├── nav.html.tera +│   ├── network_add.html.tera +│   ├── network_card.html.tera +│   ├── network_detail.html.tera +│   ├── network_list.html.tera +│   ├── network_modify.html.tera +│   ├── not_found.html.tera +│   └── shutdown.html.tera +``` + +### Environment + +The web application deployment mode is configured with the `ROCKET_ENV` environment variable: + +`export ROCKET_ENV=stage` + +Other deployment modes are `dev` and `prod`. Read the [Rocket Environment Configurations docs](https://rocket.rs/v0.4/guide/configuration/#environment) for further information. + +The WebSocket server port can be configured with `PEACH_WEB_WS` environment variable: + +`export PEACH_WEB_WS=2333` + +When not set, the value defaults to `5115`. + +Logging is made available with `env_logger`: + +`export RUST_LOG=info` + +Other logging levels include `debug`, `warn` and `error`. + +### Setup + +Clone this repo: + +`git clone https://github.com/peachcloud/peach-web.git` + +Move into the repo and compile: + +`cd peach-web` +`cargo build --release` + +Run the tests: + +`cargo test` + +Run the binary: + +`./target/release/peach-web` + +_Note: Networking functionality requires peach-network microservice to be running._ + -The peach-web stack currently consists of [Rocket](https://rocket.rs/) (Rust web framework), [Tera](https://tera.netlify.com/docs/installation/) (Rust template engine inspired by Jinja2 and the Django template language) and [Tachyons](https://tachyons.io/) (functional CSS library for humans).