From b95af521a38f550979905079001c0567f92eeb20 Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Mon, 7 Feb 2022 16:14:43 +0200 Subject: [PATCH] improve client config and fix reconnect token bug --- README.md | 41 ++++++++++++++++++++++++++++++ frontend/public/index.html | 11 ++++---- frontend/src/api/GatewayClient.js | 2 +- frontend/src/api/common.js | 3 ++- frontend/src/components/App.svelte | 26 +++++++++---------- frontend/src/config.js | 10 ++++++++ frontend/src/main.js | 2 +- routes/api.js | 2 +- 8 files changed, 74 insertions(+), 23 deletions(-) create mode 100644 README.md create mode 100644 frontend/src/config.js diff --git a/README.md b/README.md new file mode 100644 index 0000000..b3eaa77 --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +# bridge + +bridge is an extensible program that allows bridging various chat applications, providing an API that bridge clients can use. Currently, it only supports bridging Discord to the bridge API. + +# Install + +`node` and `npm` are required. `yarn` is recommended instead of `npm`. (If using yarn, replace occurrences of `npm` with `yarn`) + +``` +npm install +``` + +Before running it, you will probably want to edit the server's `config.js` to match the Discord guilds you'd like to bridge or change other settings. + +Then, to run it: + +``` +DISCORD_TOKEN="your discord token" JWT_SECRET="jwt secret" node index.js +``` + +# Building the frontend + +You may also want to build the frontend web application. + +First, install the dependencies: +``` +cd frontend +npm install +``` + +Then, open `src/config.js` in your editor and update the values to match where you're hosting the bridge's http server. You may use a reverse proxy such as NGINX. If you just want to run and use it locally, the defaults are fine. + +Once you're done tweaking the configuration, you can build it: + +``` +npm run build +``` + +# Notice + +This software may break the ToS of certain chat applications that do not allow bridging (either directly or indirectly). It is only for educational purposes and I am not responsible for any damage caused. diff --git a/frontend/public/index.html b/frontend/public/index.html index e3785ef..1620cba 100644 --- a/frontend/public/index.html +++ b/frontend/public/index.html @@ -1,16 +1,15 @@ - - + + App - - - + + - + diff --git a/frontend/src/api/GatewayClient.js b/frontend/src/api/GatewayClient.js index 2bd50fc..0264186 100644 --- a/frontend/src/api/GatewayClient.js +++ b/frontend/src/api/GatewayClient.js @@ -75,7 +75,7 @@ export default class GatewayClient { console.log("gateway: closed"); setTimeout(() => { console.log("gateway: reconnecting"); - this.connect(); + this.connect(token); }, 4000); }); } diff --git a/frontend/src/api/common.js b/frontend/src/api/common.js index e1a2225..c734ae4 100644 --- a/frontend/src/api/common.js +++ b/frontend/src/api/common.js @@ -1,3 +1,4 @@ +import { apiBase, getRuntimeConfigField } from "../config"; import APIClient from "./APIClient"; -export const apiClient = new APIClient(`${location.origin}/api/v1`, localStorage.getItem("token")); \ No newline at end of file +export const apiClient = new APIClient(apiBase, getRuntimeConfigField("token")); diff --git a/frontend/src/components/App.svelte b/frontend/src/components/App.svelte index eaa3fd9..798d07f 100644 --- a/frontend/src/components/App.svelte +++ b/frontend/src/components/App.svelte @@ -1,6 +1,7 @@