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
This commit is contained in:
Lucy C
2022-05-19 15:58:32 -06:00
committed by GitHub
parent 1023916390
commit 2b6e54da1e
5 changed files with 49 additions and 6 deletions

1
frontend/.gitignore vendored
View File

@@ -39,3 +39,4 @@ postprocess.js
/plugins
config.json
proxy.conf.json

View File

@@ -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
```

View File

@@ -14,6 +14,11 @@
"mocks": {
"maskAs": "tor",
"skipStartupAlerts": true
},
"marketplace": {
"url": "https://beta-registry-0-3.start9labs.com/",
"name": "Embassy Marketplace"
}
}
},
"gitHash": ""
}

View File

@@ -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": {

View File

@@ -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": ""
}
}
}