derekyerger / rust-ttyws

Websockets server for switch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Topics:

  • ⚙️ Rust
  • 🟨 Hyper
  • 🟥 Redis
  • 🐳 Docker

Prerequisites

docker

Docker Desktop for Mac

docker --version
# Docker version 19.03.8, build afacb8b

rustc + rustup + cargo

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustc --version
# rustc 1.44.1 (c7087fe00 2020-06-17)

rustup --version
# rustup 1.21.1 (7832b2ebe 2019-12-20)

cargo version
# cargo 1.44.1 (88ba85757 2020-06-11)

Redis

A local Redis container, running on localhost:6379

docker pull bitnami/redis

# This will eat your terminal
docker run --rm --name redis \
  -e ALLOW_EMPTY_PASSWORD=yes \
  -p 6379:6379 \
  bitnami/redis

# ctrl+c to stop

Optional

Install the redis-cli

brew install redis

redis-cli --version
# redis-cli 6.0.5

Save your terminal

# Run docker in detached mode
docker run --rm --name redis \
  -e ALLOW_EMPTY_PASSWORD=yes \
  -d -it -p 6379:6379 bitnami/redis

# Stop the container
docker stop redis

Database GUI? Visit redis://127.0.0.1:6379 in a browser. On my machine, I get prompted to open TablePlus.

Get started

# Run with:
cargo run

# Run with hot reloading:
systemfd --no-pid -s http::3000 -- cargo watch -x run

# Find previous task on a port
netstat -vanp tcp | grep 3000

Building Docker Image

docker build --rm -t rust-websocket-server .
docker images

Running

docker run --rm \
  --name rrd \
  -p 3000:3020\
  rust-websocket-server:latest

Helpful things

Remove Dangling Images

Remove those pesky <none> images when building new images

# fish-shell
docker rmi (docker images -f 'dangling=true' -q)

Remove All Stopped Containers

# fish-shell
docker rm (docker ps -a -q)

Test POST request to server

curl -X POST http://localhost:3000/echo/uppercase -d "poop"

About

Websockets server for switch


Languages

Language:Rust 93.4%Language:Dockerfile 6.6%