From 3c517bbaf56aa0fdd1e42246a69b549259a4c0c5 Mon Sep 17 00:00:00 2001 From: ading2210 Date: Fri, 2 Feb 2024 23:11:59 +0000 Subject: [PATCH] add option to capture stdout --- .github/workflows/build.yaml | 4 ++++ README.md | 14 ++++++++++++-- client/index.html | 2 +- client/javascript/main.js | 6 +++++- client/package.json | 2 +- client/tests/index.html | 7 ++----- client/tests/run.sh | 19 +++++++++++++++++-- client/tests/run_tests.py | 7 +++++-- client/tests/scripts/redirect_out.js | 11 +++++++++++ server/run.sh | 10 +++++----- server/wisp_server | 2 +- 11 files changed, 64 insertions(+), 20 deletions(-) create mode 100644 client/tests/scripts/redirect_out.js diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 51d7a27..74567d2 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -19,6 +19,10 @@ jobs: - name: run build working-directory: ./client run: ./build.sh all + + - name: run tests + working-directory: ./client + run: ./tests/run.sh || true - name: upload img uses: actions/upload-artifact@v4 diff --git a/README.md b/README.md index 38a967d..4bac323 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,17 @@ You can change the URL of the websocket proxy by using `libcurl.set_websocket`. ```js libcurl.set_websocket("ws://localhost:6001/"); ``` -If the websocket proxy URL is not set and one of the other API functions is called, an error will be thrown. +If the websocket proxy URL is not set and one of the other API functions is called, an error will be thrown. Note that this URL must end with a trailing slash. + +### Getting Libcurl's Output: +If you want more information about a connection, you can pass the `_libcurl_verbose` argument to the `libcurl.fetch` function. +```js +await libcurl.fetch("https://example.com", {_libcurl_verbose: 1}); +``` +By default this will print the output to the browser console, but you can set `libcurl.stdout` and `libcurl.stderr` to intercept these messages. This callback will be executed on every line of text that libcurl outputs. +```js +libcurl.stderr = (text) => {document.body.innerHTML += text}; +``` ## Proxy Server: The proxy server consists of a standard [Wisp](https://github.com/MercuryWorkshop/wisp-protocol) server, allowing multiple TCP connections to share the same websocket. @@ -93,7 +103,7 @@ To host the proxy server, run the following commands: ``` git clone https://github.com/ading2210/libcurl.js --recursive cd libcurl.js -STATIC=$(pwd)/client server/run.sh +server/run.sh --static=./client ``` You can use the `HOST` and `PORT` environment variables to control the hostname and port that the proxy server listens on. diff --git a/client/index.html b/client/index.html index cc83238..37c5d40 100644 --- a/client/index.html +++ b/client/index.html @@ -3,7 +3,7 @@ - +