PaluMacil / wasm-component

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WASM Component

Summary

The purpose of WASM Component is to provide a simple, opinionated demo of a project layout using protobufs (v3), frontend GRPC over websockets, Go's WASM support, and components through the standard library html/template. Less novel concepts which are often part of a website are out of scope for this demonstration. This includes any sort of datastore, authentication, authorization, or advanced logging capabilities.

In order to provide style without adding noise to the html, Pico.css is utilized. Communication via GRPC over wasm uses the tarndt/wasmws library, and the version 2 of dominikh/go-js-dom provides dom convenience functions.

Dependencies

Basic

  • Go: language and compiler
  • Git: version control system

Specific

See links for alternative installation methods or to verify the latest instructions and versions. Otherwise, run the commands listed.

  • Task: a friendly, simple task runner
    • go install github.com/go-task/task/v3/cmd/task@latest
  • protobuf and Go plugins: protoc, a protobuf generator for use in GRPC
    • go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
    • go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
  • (optional) NSS Tools: to make Chrome accept the CA used to sign the dev certs.

Setup

Setup assumes that your dependencies are available in your PATH. If you installed the specific dependencies via go install, for instance go install github.com/go-task/task/v3/cmd/task@latest then you need to make sure your GOBIN is on your path. You can confirm the location that the Go command currently uses with go env GOBIN. If you would like to use a different location, you can set this environmental variable using your system's tools. On Ubuntu, for instance, you might add the text export GOBIN=/opt/gobin to your ~/.bashrc file.

  1. git clone

Project Binaries

server

An example server with embedded asset (single-file production build) or live reload mode (uses filesystem as editing occurs). This could use a third party tool like air, but the intent is to be able to live reload templates (only components that change and their subordinate tree) without restarting the server and reloading the frontend (which would lose state) unless the Go code changes, which would always cause a server restart as well as a client restart. Pieces of this example should be moved to a dedicated repo over time.

client

An example companion application which gets compiled to wasm and added to the static files embedded into the server. binary.

Additional resources:

certman

The intent of certman is to provide locally acceptable certificates for serving https in a way that tools like a browser or curl accept as valid for dev domains. This should be moved out of this repo to a more appropriate home (something less specific to components).

Resources for accomplishing this task:

Once certman is removed from this repo, the concept will be expanded to managing /etc/hosts, a reverse proxy from

I could use libpam0g-dev to authenticate a machine user via msteinert/pam to authenticate into a control panel served at local.rhyvu.com installed and from there a user could list domains to add. Each domain would be added to /etc/hosts (via a setuid utility), have a certificate generated from the CA, and then the user would be able to add base href (for instance / or /api) and the upstream url. In the future, the web interface could also provide additional features such as stripping or transforming parts of the url before sending the data upstream, or there could be convenience utilities for serving static files.

Usage (in this example, for workout.dev.rhyvu.com)

  • gen a CA task certman -- init
  • create cert task certman -- workout workout.dev.rhyvu.com
  • convert pem to pk12 openssl pkcs12 -export -out workout.pkcs12 -in workout.crt -inkey workout.key
  • (might not be correct command as it doesn't seem to set as trusted or as an authority, but you can manually add in Settings > Privacy and Security > Manage certificates > Authorities) add ca to Chrome pk12util -d sql:$HOME/.pki/nssdb -i /var/opt/certman/workout.pkcs12
  • list personal certs certutil -d sql:$HOME/.pki/nssdb -L
  • add /etc/hosts entries
    • 127.0.0.1 dev.rhyvu.com
    • 127.0.0.1 accounts.dev.rhyvu.com
    • 127.0.0.1 workout.dev.rhyvu.com

License and Purpose

This project is licensed permissively with a standard MIT license which allows both commercial and personal use. However, the purpose of this project is for demonstration purposes, so depending upon this code for production usage is not recommended. If any of the ideas here are used in a broader project, links will be listed below.

About

License:MIT License


Languages

Language:JavaScript 56.2%Language:Go 43.8%