diff --git a/frontend/README.md b/frontend/README.md index ba6980c7..30ec4011 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -2,6 +2,12 @@ ## Quickstart +Copy environment variables from the sample file: + +```sh +cp sample.env.local .env.local +``` + Install dependencies: ```sh @@ -16,6 +22,9 @@ yarn start-dev This will open `localhost:9870` in a new tab in your default browser. +To develop against a local instance of the backend API, +follow instructions for deploying to a local Docker instance. Update `API_BASE_URL` and then restart the dev server. + ## Scripts | `yarn ` | | @@ -32,11 +41,13 @@ This will open `localhost:9870` in a new tab in your default browser. Tests assertions are written in [Chai](https://www.chaijs.com/api/bdd/). To watch for file changes while running tests: + ```sh yarn test --watch ``` To run tests in multiple browsers: + ```sh yarn test --browsers chromium firefox webkit ``` diff --git a/frontend/package.json b/frontend/package.json index 25409525..0317fd8d 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -27,6 +27,7 @@ "@web/test-runner-playwright": "^0.8.8", "autoprefixer": "^10.3.6", "css-loader": "^6.3.0", + "dotenv": "^10.0.0", "eslint": "^8.2.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-lit": "^1.6.1", diff --git a/frontend/sample.env.local b/frontend/sample.env.local new file mode 100644 index 00000000..a3183a7d --- /dev/null +++ b/frontend/sample.env.local @@ -0,0 +1 @@ +API_BASE_URL='http://btrix.cloud' diff --git a/frontend/webpack.config.js b/frontend/webpack.config.js index bfcbf0fd..d9634390 100644 --- a/frontend/webpack.config.js +++ b/frontend/webpack.config.js @@ -2,7 +2,13 @@ const path = require("path"); const ESLintPlugin = require("eslint-webpack-plugin"); -const backendUrl = new URL("http://btrix.cloud/"); +const isDevServer = process.env.WEBPACK_SERVE; + +require("dotenv").config({ + path: path.resolve(process.cwd(), `.env${isDevServer ? `.local` : ""}`), +}); + +const backendUrl = new URL(process.env.API_BASE_URL || "http://btrix.cloud/"); module.exports = { entry: "./src/index.js", diff --git a/frontend/yarn.lock b/frontend/yarn.lock index 31c72d79..e81f3f48 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -1585,6 +1585,11 @@ doctrine@^3.0.0: dependencies: esutils "^2.0.2" +dotenv@^10.0.0: + version "10.0.0" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81" + integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q== + ee-first@1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"