-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b76d725
commit 864616f
Showing
21 changed files
with
270 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"vue-demo-store": minor | ||
--- | ||
|
||
Add maintenance mode page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@shopware-pwa/helpers-next": minor | ||
--- | ||
|
||
Add isMaintenanceMode to check if backend is available |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@shopware/api-client": minor | ||
--- | ||
|
||
Add error and success callbacks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
apps/docs/src/getting-started/features/maintenance-mode.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
--- | ||
head: | ||
- - meta | ||
- name: og:title | ||
content: "Maintenance mode - Shopware Frontends" | ||
- - meta | ||
- name: og:description | ||
content: "Example of implementation maintenance mode page" | ||
- - meta | ||
- name: og:image | ||
content: "https://frontends-og-image.vercel.app/Integration:%20**Maintenance%20Mode**?fontSize=100px" | ||
--- | ||
|
||
# Maintenance mode | ||
|
||
You can activate the maintenance mode of your store by selecting your sales channel and then activating the maintenance mode under Status | ||
|
||
## Detecting maintenance mode via API | ||
|
||
Maintenance mode is returned as an error from all of the endpoints. We can detect it by using `onErrorHandler` callback function in `createAPIClient` init api method. | ||
|
||
```ts | ||
const apiClient = createAPIClient({ | ||
baseURL: shopwareEndpoint, | ||
accessToken: shopwareAccessToken, | ||
contextToken: Cookies.get("sw-context-token"), | ||
onContextChanged(newContextToken) { | ||
Cookies.set("sw-context-token", newContextToken, { | ||
expires: 365, // days | ||
path: "/", | ||
sameSite: "lax", | ||
}); | ||
}, | ||
onErrorHandler(response) { | ||
const error = response._data?.errors?.find((element) => { | ||
return element.code === "FRAMEWORK__API_SALES_CHANNEL_MAINTENANCE_MODE"; | ||
}); | ||
}, | ||
}); | ||
``` | ||
|
||
## Displaying maintenance page | ||
|
||
:::warning | ||
This example is for Nuxt 3 apps | ||
::: | ||
|
||
### Throwing MAINTENANCE_MODE error | ||
|
||
Every error thrown within the application is automatically caught and the `error.vue` page is displayed. | ||
|
||
```ts | ||
onErrorHandler(response) { | ||
const error = response._data?.errors?.find((element) => { | ||
return element.code === "FRAMEWORK__API_SALES_CHANNEL_MAINTENANCE_MODE"; | ||
}); | ||
|
||
if (error) { | ||
throw createError({ | ||
statusCode: 503, | ||
statusMessage: "MAINTENANCE_MODE", | ||
}); | ||
} | ||
}, | ||
``` | ||
|
||
### Displaying maintenance mode page | ||
|
||
```vue | ||
// error.vue | ||
<script setup lang="ts"> | ||
const props = defineProps<{ | ||
error: { | ||
statusCode: number; | ||
statusMessage: string; | ||
message: string; | ||
}; | ||
}>(); | ||
const isMaintenanceMode = computed(() => { | ||
return props.error.statusMessage === "MAINTENANCE_MODE"; | ||
}); | ||
</script> | ||
<template> | ||
<div v-if="isMaintenanceMode">Maintenance Mode Page Content</div> | ||
</template> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { isMaintenanceMode } from "./index"; | ||
|
||
describe("isMaintenanceMode", () => { | ||
it("should return true", () => { | ||
expect( | ||
isMaintenanceMode([ | ||
{ | ||
status: "503", | ||
code: "FRAMEWORK__API_SALES_CHANNEL_MAINTENANCE_MODE", | ||
title: "Service Unavailable", | ||
detail: "The sales channel is in maintenance mode.", | ||
meta: { parameters: [] }, | ||
}, | ||
]), | ||
).toBe(true); | ||
}); | ||
|
||
it("should return false", () => { | ||
expect( | ||
isMaintenanceMode([ | ||
{ | ||
status: "404", | ||
code: "test", | ||
title: "Not Found", | ||
}, | ||
]), | ||
).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export function isMaintenanceMode< | ||
T extends { | ||
code?: string; | ||
}, | ||
>(errors: [T]): boolean { | ||
return ( | ||
!!errors.find((element) => { | ||
return ( | ||
element.code === "FRAMEWORK__API_SALES_CHANNEL_MAINTENANCE_MODE" ?? | ||
false | ||
); | ||
}) ?? false | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.