Peter Makowski has proposed merging 
~petermakowski/maas-site-manager:add-VITE_USE_MOCK_DATA-env-var into 
maas-site-manager:main.

Commit message:
add VITE_USE_MOCK_DATA env var

Requested reviews:
  MAAS Committers (maas-committers)

For more details, see:
https://code.launchpad.net/~petermakowski/maas-site-manager/+git/site-manager/+merge/442286

QA Steps
- follow readme instructions and make sure mock server is enabled by default 
and you can disable it by following instructions to run local backend
-- 
Your team MAAS Committers is requested to review the proposed merge of 
~petermakowski/maas-site-manager:add-VITE_USE_MOCK_DATA-env-var into 
maas-site-manager:main.
diff --git a/.env b/.env
index 8822115..7c416c2 100644
--- a/.env
+++ b/.env
@@ -1,6 +1,5 @@
 VITE_UI_PORT=8405
 VITE_API_URL=http://localhost:8000
 VITE_SENTRY_DSN="https://7236de0eb0354e2099b7efd7d310a...@sentry.is.canonical.com/60";
-
 SECRET_KEY="09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7"
 # XXX: Replace this, and all affected data, in actual release! using something like `openssl rand -hex 32`
\ No newline at end of file
diff --git a/.env.development b/.env.development
new file mode 100644
index 0000000..9bbcc67
--- /dev/null
+++ b/.env.development
@@ -0,0 +1 @@
+VITE_USE_MOCK_DATA=true
\ No newline at end of file
diff --git a/.env.production b/.env.production
new file mode 100644
index 0000000..f8679f9
--- /dev/null
+++ b/.env.production
@@ -0,0 +1 @@
+VITE_USE_MOCK_DATA=false
\ No newline at end of file
diff --git a/frontend/README.md b/frontend/README.md
index d513d9c..78fde6d 100644
--- a/frontend/README.md
+++ b/frontend/README.md
@@ -4,36 +4,24 @@ This is the frontend for the [MAAS Site Manager Project](https://launchpad.net/m
 
 ## How to run a development environment
 
-First start the backend
+The quickest way to get started is run frontend with mock backend which is enabled by default.
 
 ```bash
-$LP_USERNAME=your-username
-sudo apt-get install tox
-
-git clone https://code.launchpad.net/~maas-committers/maas-site-manager/+git/site-manager
-
-cd site-manager
-
-docker run --rm -it \
-    -p 5432:5432 \
-    -e POSTGRES_PASSWORD=pass \
-    --name postgres \
-    postgres:14
-
-tox -e run
+yarn dev
 ```
 
-Then run this frontend
+### Using a local backend
+
+Setup local environment variables
 
 ```bash
-git clone https://code.launchpad.net/~maas-committers/maas-site-manager/+git/site-manager-frontend
-cd site-manager-frontend
+cp .env.development .env.local.development
+```
 
-# TODO, possibly edit an env/config file to point to a local backend
+Set `VITE_USE_MOCK_DATA` to `false` in `.env.local.development`.
 
-yarn  # install dependencies
-yarn run dev
-```
+Start the backend
+[MAAS Site Manager Backend Readme](/backend/README.md).
 
 ## Project conventions
 
diff --git a/frontend/src/constants.ts b/frontend/src/constants.ts
index f793ce5..99b7c2a 100644
--- a/frontend/src/constants.ts
+++ b/frontend/src/constants.ts
@@ -1 +1,2 @@
-export const isDev = process.env.NODE_ENV === "development";
+export const isDev = import.meta.env.DEV;
+export const useMockData = import.meta.env.VITE_USE_MOCK_DATA === "true";
diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx
index d10c7e9..e65a61b 100644
--- a/frontend/src/main.tsx
+++ b/frontend/src/main.tsx
@@ -6,10 +6,10 @@ import * as ReactDOM from "react-dom/client";
 import packageInfo from "../package.json";
 
 import App from "./App";
-import { isDev } from "./constants";
+import { useMockData } from "./constants";
 
 /* c8 ignore next 4 */
-if (isDev) {
+if (useMockData) {
   const { worker } = await import("./mocks/browser");
   await worker.start();
 }
diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts
index 43be29c..ad48ac2 100644
--- a/frontend/vite.config.ts
+++ b/frontend/vite.config.ts
@@ -12,6 +12,7 @@ const commitHash = require("child_process").execSync("git rev-parse --short HEAD
 
 // https://vitejs.dev/config/
 export default defineConfig({
+  envDir: "../",
   define: { "import.meta.env.VITE_APP_VERSION": JSON.stringify(commitHash) },
   plugins: [
     react(),
-- 
Mailing list: https://launchpad.net/~sts-sponsors
Post to     : sts-sponsors@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sts-sponsors
More help   : https://help.launchpad.net/ListHelp

Reply via email to