From 2b6e54da1e3f62e0a88c7d7e1b8abc2563b9941f Mon Sep 17 00:00:00 2001 From: Lucy C <12953208+elvece@users.noreply.github.com> Date: Thu, 19 May 2022 15:58:32 -0600 Subject: [PATCH] Proxy local frontend to remote backend (#1452) * add server proxy configurations * change address to host due to compliation warning * adjust config sample to more accurately reflect production version --- frontend/.gitignore | 1 + frontend/README.md | 26 ++++++++++++++++++++++++-- frontend/config-sample.json | 7 ++++++- frontend/package.json | 7 ++++--- frontend/proxy.conf.json.sample | 14 ++++++++++++++ 5 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 frontend/proxy.conf.json.sample diff --git a/frontend/.gitignore b/frontend/.gitignore index abcb07f90..b1c5a5c90 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -39,3 +39,4 @@ postprocess.js /plugins config.json +proxy.conf.json \ No newline at end of file diff --git a/frontend/README.md b/frontend/README.md index 760e90a17..ec99ff7c2 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -25,6 +25,8 @@ v8.0.0 ## Running locally with mocks +1. Clone the repository + ``` git clone https://github.com/Start9Labs/embassy-os.git cd embassy-os @@ -34,7 +36,7 @@ npm ci npm run build:deps ``` -Copy `config-sample.json` and its contents to a new file `config.json`. +2. Copy `config-sample.json` and its contents to a new file `config.json`. ``` cp config-sample.json config.json @@ -43,10 +45,30 @@ cp config-sample.json config.json By default, "useMocks" is set to `true`. Valid values for "maskAs" are `tor` and `lan`. -**Start the development server(s)** +3. Start the development server(s) ``` npm run start:ui npm run start:setup-wizard npm run start:diagnostic-ui ``` + +## Running locally with proxied backend + +This section enables you to run a local frontend with a remote backend (eg. hosted on a live Embassy). It assumes you have completed Step 1 and Step 2 in the [section above](#running-locally-with-mocks) + +1. Set `useMocks: true` in `config.json` + +2. Create a proxy configuration file from the sample: + +``` +cp proxy.conf.json.sample proxy.conf.json +``` + +3. Change the target address to desired IP address in `proxy.conf.json` + +4. Start the development server + +``` +npm run start:ui:proxy +``` diff --git a/frontend/config-sample.json b/frontend/config-sample.json index 597ee7714..1727d1e5c 100644 --- a/frontend/config-sample.json +++ b/frontend/config-sample.json @@ -14,6 +14,11 @@ "mocks": { "maskAs": "tor", "skipStartupAlerts": true + }, + "marketplace": { + "url": "https://beta-registry-0-3.start9labs.com/", + "name": "Embassy Marketplace" } - } + }, + "gitHash": "" } diff --git a/frontend/package.json b/frontend/package.json index f49d127b4..c40f28eb3 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -15,9 +15,10 @@ "build:setup-wizard": "ng run setup-wizard:build", "build:ui": "ng run ui:build && tsc projects/ui/postprocess.ts && node projects/ui/postprocess.js && git log | head -n1 > dist/ui/git-hash.txt", "build:all": "npm run build:deps && npm run build:diagnostic-ui && npm run build:setup-wizard && npm run build:ui", - "start:diagnostic-ui": "npm run-script build-config && ionic serve --project diagnostic-ui --address 0.0.0.0", - "start:setup-wizard": "npm run-script build-config && ionic serve --project setup-wizard --address 0.0.0.0", - "start:ui": "npm run-script build-config && ionic serve --project ui --ip --address 0.0.0.0", + "start:diagnostic-ui": "npm run-script build-config && ionic serve --project diagnostic-ui --host 0.0.0.0", + "start:setup-wizard": "npm run-script build-config && ionic serve --project setup-wizard --host 0.0.0.0", + "start:ui": "npm run-script build-config && ionic serve --project ui --ip --host 0.0.0.0", + "start:ui:proxy": "npm run-script build-config && ionic serve --project ui --ip --host 0.0.0.0 -- --proxy-config proxy.conf.json", "build-config": "node build-config.js" }, "dependencies": { diff --git a/frontend/proxy.conf.json.sample b/frontend/proxy.conf.json.sample new file mode 100644 index 000000000..e97124bd2 --- /dev/null +++ b/frontend/proxy.conf.json.sample @@ -0,0 +1,14 @@ +{ + "/rpc/v1": { + "target": "http://localhost:8100/rpc/v1" + }, + "/ws": { + "target": "http://localhost:8100/ws" + }, + "/public/*": { + "target": "http://localhost:8100/public", + "pathRewrite": { + "^/public": "" + } + } +} \ No newline at end of file