Skip to content

Commit

Permalink
feat(vue-demo): add private shopwareEndpoint (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdanilowicz authored Jul 21, 2023
1 parent 8e499e3 commit faf28ca
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/dull-buses-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vue-demo-store": minor
---

Add private `shopwareEndpoint`
5 changes: 5 additions & 0 deletions .changeset/gorgeous-keys-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shopware-pwa/nuxt3-module": minor
---

Add private `shopwareEndpoint` config for SSR instance creation
28 changes: 28 additions & 0 deletions apps/docs/src/getting-started/templates/custom-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,34 @@ export default {
};
```

## Shopware Endpoint on the SSR mode

It may happen that for SSR and CSR, you need two different shopware endpoints. One of the most common situations is when you are using an internal network for communication between apps.

```
Server URL to the backend: http://shopware (not exposed)
Client URL to the backend https://demo-frontends.shopware.store (exposed)
```

If you are using the Nuxt plugin, you can set private and public envs:

```
NUXT_SHOPWARE_SHOPWARE_ENDPOINT=http://shopware
NUXT_PUBLIC_SHOPWARE_SHOPWARE_ENDPOINT=https://demo-frontends.shopware.store
```

Otherwise, make sure that you are setting different values on the create instance phase

```ts
const instance = createInstance({
endpoint: ssrValue || clientValue,
accessToken: options.shopwareAccessToken,
timeout: options.shopwareApiClient?.timeout || 5000,
contextToken: contextToken.value,
languageId: languageId.value,
});
```

## Next steps

After your setup, you can follow our building guides to get started with Shopware Frontends
Expand Down
7 changes: 6 additions & 1 deletion packages/nuxt3-module/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ const ShopwarePlugin = {
);
}

/**
* Server config has bigger prio than client
*/
const instance = createInstance({
endpoint: runtimeConfig.public.shopware.shopwareEndpoint,
endpoint:
runtimeConfig?.shopware?.shopwareEndpoint ||
runtimeConfig.public.shopware.shopwareEndpoint,
accessToken: runtimeConfig.public.shopware.shopwareAccessToken,
timeout: runtimeConfig.public.shopware.shopwareAccessToken || 10000,
auth: {
Expand Down
7 changes: 7 additions & 0 deletions templates/vue-demo-store/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ import { VueDisableInputsBeforeMount } from "vite-vue-plugin-disable-inputs";
// https://v3.nuxtjs.org/docs/directory-structure/nuxt.config
export default defineNuxtConfig({
runtimeConfig: {
shopware: {
/**
* SSR Shopware Endpoint
* More here: https://frontends.shopware.com/getting-started/templates/custom-project.html#shopware-endpoint-on-the-ssr-mode
*/
shopwareEndpoint: "",
},
public: {
shopware: {
shopwareEndpoint: "https://demo-frontends.shopware.store",
Expand Down

2 comments on commit faf28ca

@vercel
Copy link

@vercel vercel bot commented on faf28ca Jul 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

frontends-demo – ./templates/vue-demo-store

frontends-demo-git-main-shopware-frontends.vercel.app
frontends-demo-shopware-frontends.vercel.app
frontends-demo.vercel.app

@vercel
Copy link

@vercel vercel bot commented on faf28ca Jul 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.