From a5029acad57daa2e8e8b1d443cc1efe0e5f43021 Mon Sep 17 00:00:00 2001 From: Jian Liao Date: Tue, 17 May 2022 17:29:53 -0700 Subject: [PATCH] Rebuild Readme.md and fix some typos --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 95 +++++++++++++++++++++++++++++++++++++++-------------- src/main.rs | 4 +-- 4 files changed, 75 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d4f2afb..d98595b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -647,7 +647,7 @@ dependencies = [ [[package]] name = "lcs-png-diff-server" -version = "0.1.3" +version = "0.1.4" dependencies = [ "axum", "axum-extra", diff --git a/Cargo.toml b/Cargo.toml index a4ca23c..959da7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lcs-png-diff-server" -version = "0.1.3" +version = "0.1.4" edition = "2021" documentation = "https://github.com/jianliao/lcs-png-diff-server-rs" homepage = "https://github.com/jianliao/lcs-png-diff-server-rs" diff --git a/README.md b/README.md index 7e83fd2..0b932cc 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,29 @@ # lcs-png-diff-server -Pass in before and after bitmap URL, then the server will generate lcs diff png and return the diff result URL in response. +Pass in before and after bitmap URL, and then the server will generate LCS diff png and return the diff result URL in response. -## Server start options +## Getting Started -### Start server +### Install and start server ``` bash -lcs-png-diff-server -``` -or -``` bash -docker run --rm -it -p 8080:8080 jianliao/lcs-png-diff-server:latest -``` - -### Customize response URL +$ cargo install lcs-png-diff-server -``` bash -HOST_INFO=https://localhost:443/ lcs-png-diff-server -``` -or -``` bash -docker run --rm -it -e HOST_INFO=https://localhost:443/ -p 8080:8080 jianliao/lcs-png-diff-server:latest +$ lcs-png-diff-server ``` -## Example Request and Response - -### Request payload +### Request ``` bash curl \ -d '{ - "before_png": "http://localhost:3000/fixtures/slider.png", - "after_png": "http://localhost:3000/fixtures/slider_after.png" + "before_png": "https://jianliao.github.io/lcs-test-pngs/before.png", + "after_png": "https://jianliao.github.io/lcs-test-pngs/after.png" }' \ -H 'Content-Type: application/json' \ -X POST http://localhost:8080/api/diff ``` -### Response payload +### Example response payload ``` json { @@ -45,6 +31,67 @@ curl \ } ``` +## Server startup options + +``` bash +$ lcs-png-diff-server --help +lcs-png-diff-server +A server for generating diff bitmaps from png files + +USAGE: + lcs-png-diff-server [OPTIONS] + +OPTIONS: + -a, --addr set the listen addr [default: 0.0.0.0] + -h, --help Print help information + -l, --log set the log level [default: info] + -p, --port set the listen port [default: 8080] + --static-dir set the directory where static files are to be found [default: + ./assets] +``` + +### Customize the hostname of the response URL + +You can customize the hostname of the diff result URL by setting the `HOST_INFO` environment variable. + +``` bash +HOST_INFO=https://localhost:443/ lcs-png-diff-server +``` + +## Docker + +[jianliao/lcs-png-diff-server](https://hub.docker.com/repository/docker/jianliao/lcs-png-diff-server) is a demo-only docker image. CORS had enabled for GET and POST. + +### Start server + +``` bash +$ docker run --rm -it -p 8080:8080 jianliao/lcs-png-diff-server:0.1.4 +``` + +### Print CLI help + +``` bash +$ docker run --rm -it jianliao/lcs-png-diff-server:0.1.4 --help +``` + +### Change port number + +``` bash +$ docker run --rm -it -p 3000:3000 jianliao/lcs-png-diff-server:0.1.4 -p 3000 +``` + +### Change log level + +``` bash +$ docker run --rm -it -p 8080:8080 jianliao/lcs-png-diff-server:0.1.4 -l debug +``` + +### Customize response URL + +``` bash +$ docker run --rm -it -e HOST_INFO=https://domainname/ -p 8080:8080 jianliao/lcs-png-diff-server:0.1.4 +``` + ## LICENSE -Apache License Version 2.0 \ No newline at end of file +Apache License Version 2.0 diff --git a/src/main.rs b/src/main.rs index 52619ce..2111984 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,8 +25,8 @@ use uuid::Uuid; #[derive(Parser, Debug)] #[clap( - name = "lcs-diff-server", - about = "A server for generating diff bitmap from png files" + name = "lcs-png-diff-server", + about = "A server for generating diff bitmaps from png files" )] struct Opt { /// set the log level