Skip to content

Commit 72c23d6

Browse files
committed
Merge branch 'nik_dev_setup_for_ui' into 'master'
Support .env for dev/debug purposes. Clarify how to start Platform UI locally for dev/debugging, with predefined JWT See merge request postgres-ai/database-lab!853
2 parents dc1dae7 + 2ac110a commit 72c23d6

File tree

7 files changed

+24
-12
lines changed

7 files changed

+24
-12
lines changed

ui/README.md

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Database Lab Engine and Database Lab Engine UI
1+
# Database Lab Engine UI and DBLab Platform UI
22

3-
## Database Lab - thin database clones for faster development
3+
## DBLab - thin database clones and database branching for faster development
44

55
_Proceed to [Database Lab Engine repository](https://gitlab.com/postgres-ai/database-lab) for more information about technology itself._
66
Database Lab Engine (DLE) is an open-source (Apache 2.0) technology that allows blazing-fast cloning of Postgres databases of any size in seconds. This helps solve many problems such as:
@@ -27,24 +27,22 @@ At the root:
2727
- `<npm command> -w <package-name>` - for specific package
2828

2929
#### Examples
30-
3130
- `npm ci -ws` - install deps of all packages
3231
- `npm run build -ws` - build all packages
3332
- `npm run start -w @postgres.ai/platform` - run platform UI locally in dev mode
3433
- `npm run start -w @postgres.ai/ce` - run community edition UI locally in dev mode
3534

3635
_Important note: don't use commands for `@postgres.ai/shared` - it's dependent package, which can't be running or built_
3736

38-
### How to start "platform"
39-
40-
- `cd ui`
41-
- `npm ci -ws` - install dependencies, must be done once to install dependencies for all packages
42-
- `source packages/platform/deploy/configs/production.sh` - set up environment variables, should be run for each new terminal session
43-
- `npm run start -w @postgres.ai/platform` - start dev server
44-
- To sign in locally - sign in on [console.postgres.ai](https://console.postgres.ai) and copy `token` from Local Storage to your localhost's Local Storage
37+
### How to start Platform UI with a predefined JWT token
38+
- `cd ui/packages/platform`
39+
- `cp .env_example_dev .env`
40+
- edit `.env` setting:
41+
- `REACT_APP_API_URL_PREFIX` to point to dev API server (e.g., staging API server: `https://v2.postgres.ai/api/general`).
42+
- `REACT_APP_TOKEN_DEBUG` to have your JWT ready work with the same server. Note that it has an expiration date so it needs to be periodically refreshed.
43+
- `pnpm run start` - start Platform for local debugging/development
4544

4645
### How to start "ce"
47-
4846
- `cd ui`
4947
- `npm ci -ws` - install dependencies, must be done once to install dependencies for all packages
5048
- `npm run start -w @postgres.ai/ce` - start dev server

ui/packages/platform/.env_example_dev

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
REACT_APP_API_URL_PREFIX=https://v2.postgres.ai/api/general
2+
REACT_APP_TOKEN_DEBUG=__YOUR_JWT_TOKEN_FROM_STAGING__

ui/packages/platform/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

ui/packages/platform/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"d3-flame-graph": "^2.1.3",
4444
"date-fns": "^2.22.1",
4545
"dompurify": "^2.0.12",
46+
"dotenv": "^10.0.0",
4647
"es6-promise": "^4.2.8",
4748
"formik": "^2.2.9",
4849
"get-user-locale": "^1.4.0",

ui/packages/platform/src/api/api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function encodeData(data) {
1717
class Api {
1818
constructor(setting) {
1919
this.server = setting.server
20-
this.apiServer = setting.apiServer
20+
this.apiServer = process.env.REACT_APP_API_URL_PREFIX || setting.apiServer // if set in .env (e.g., for dev/debug), use it
2121
}
2222

2323
get(url, query, options) {

ui/packages/platform/src/config/env.ts

+7
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ export const SENTRY_DSN = process.env.REACT_APP_SENTRY_DSN
1010
export const API_URL_PREFIX = process.env.REACT_APP_API_SERVER ?? ''
1111
export const WS_URL_PREFIX = process.env.REACT_APP_WS_URL_PREFIX ?? ''
1212
export const BUILD_TIMESTAMP = process.env.BUILD_TIMESTAMP
13+
14+
// For debug purposes or during development, allow to pre-set the JWT token.
15+
const token = process.env.REACT_APP_TOKEN_DEBUG;
16+
if (token) {
17+
localStorage.setItem('token', token);
18+
console.warn('WARNING: JWT token is being set from the environment variable. This appears to be a debugging or development setup.');
19+
}

ui/pnpm-lock.yaml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)