Skip to content

Commit

Permalink
Allow msw bypass (#246)
Browse files Browse the repository at this point in the history
* add new variable to hold the url to the local umbraco instance

* set api base-url if msw is turned off

* add instructions how to use local umbraco instance

* set baseurl for e2e mode

Co-authored-by: Mads Rasmussen <[email protected]>
  • Loading branch information
iOvergaard and madsrasmussen authored Nov 14, 2022
1 parent ab9a6af commit e568be5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copy this to .env.local and change what you want to test.
VITE_UMBRACO_USE_MSW=on # on = turns on MSW, off = disables all mock handlers
VITE_UMBRACO_API_URL=http://localhost:9000
VITE_UMBRACO_INSTALL_STATUS=running # running or must-install or must-upgrade
3 changes: 2 additions & 1 deletion .env.e2e
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Copy this to .env.local and change what you want to test.
VITE_UMBRACO_USE_MSW=off
VITE_UMBRACO_USE_MSW=off # Playwright handles the mocking itself (using msw but it starts it up manually)
VITE_UMBRACO_API_URL=
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ VITE_UMBRACO_INSTALL_STATUS=must-install

## Environments

### Development

The development environment is the default environment and is used when running `npm run dev`. All API calls are mocked and the Umbraco backoffice is served from the `src` folder.

### Run against a local Umbraco instance

Create a `.env.local` file and set the following variables:

```bash
VITE_UMBRACO_API_URL=http://localhost:5000 # This will be the URL to your Umbraco instance
VITE_UMBRACO_USE_MSW=off # Indicate that you want all API calls to bypass MSW (mock-service-worker)
```

### Static website

See the Main branch in action here as an [Azure Static Web App](https://ashy-bay-09f36a803.1.azurestaticapps.net/). The deploy runs automatically every time the `main` branch is updated. It uses mocked responses from the Umbraco API to simulate the site just like the local development environment.
Expand Down
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class UmbApp extends UmbContextProviderMixin(LitElement) {
async connectedCallback() {
super.connectedCallback();

OpenAPI.BASE = '';
OpenAPI.BASE = import.meta.env.VITE_UMBRACO_USE_MSW === 'on' ? '' : import.meta.env.VITE_UMBRACO_API_URL;
OpenAPI.WITH_CREDENTIALS = true;

await this._setInitStatus();
Expand Down
2 changes: 1 addition & 1 deletion src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

interface ImportMetaEnv {
VITE_UMBRACO_INSTALL_STATUS: 'running' | 'must-upgrade' | 'must-install';
VITE_UMBRACO_INSTALL_PRECONFIGURED: string;
VITE_UMBRACO_API_URL: string;
VITE_UMBRACO_USE_MSW: 'on' | 'off';
}

0 comments on commit e568be5

Please sign in to comment.