0

我正试图让斯巴达克斯与 SSR 合作。打开默认 URL http://localhost:4200时,店面按预期呈现,但仅在我先清除站点数据之后。当我尝试浏览店面时,API 调用失败并显示 504(网关超时)。Chrome 开发工具表明错误发生在服务工作者中。此时,我想知道我是否错误地配置了 Spartacus。当使用yarn start而不是yarn serve:ssr运行 Spartacus 时,我可以加载主页并正常浏览网站。

OS: Ubuntu 16.04.6 LTS
Chrome Version: 73.0.3683.75
Node version: 11.15.0
Angular CLI version: 8.3.8
Yarn version: 1.19.1
ng new ssr-spartacus-app --style=scss
cd ssr-spartacus-app
ng add @spartacus/schematics --baseUrl https://localhost:9002 --baseSite cmssiteuid --pwa --ssr
rm src/app/app.component.html
echo "<cx-storefront>Loading...</cx-storefront>" > src/app/app.component.html
yarn build:ssr
yarn serve:ssr

在运行 yarn build:ssr 之前,我对 app.module.ts 文件进行了以下更改:

      context: {
        baseSite: ['cmssiteuid'],
      },

      authentication: {
        client_id: 'mobile_android',
        client_secret: 'secret',
      },
      context: {
        urlParameters: ['baseSite', 'language', 'currency'],
        baseSite: ['cmssiteuid'],
      },

我还将anonymousConsents 设置为false。将此设置为 true,我得到了很多 CORs 错误。

如果现在已经为此挠头了一会儿,我希望对斯巴达克斯内部运作有更多了解的人可以阐明为什么斯巴达克斯在 SSR 上表现得这样。

4

3 回答 3

0

I'm not sure that I can give you some certain recipe to fix the issue, obviously I need more details and logs relates to your problem, but still, based on my experience I can share with you some tips and tricks about how we should play with such issues (which relates to SSR).

Some set of theory which relates to SSR

Practical approaches for debugging SSR

Common set of theory to ensure that application has been configured correctly

于 2020-06-24T16:26:14.320 回答
0

如果您在访问 API 服务后收到 504,则需要检查您的 API 日志。

如果您有错误日志:

{"instant":{"epochSecond":1644915623,"nanoOfSecond":929833000},"thread":"hybrisHTTP1","level":"ERROR","loggerName":"org.springframework.web.servlet.DispatcherServlet","message":"Context initialization failed","thrown":{"commonElementCount":0,"localizedMessage":"Error creating bean with name 'cartEntriesController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'defaultStockValidator' defined in ServletContext resource [/WEB-INF/config/v2/validators-v2-spring.xml]: Unsatisfied dependency expressed through constructor parameter 0: Could not convert argument value of type [de.hybris.platform.ycommercewebservices.stock.impl.DefaultCommerceStockFacade] to required type [de.hybris.platform.commercewebservices.core.stock.CommerceStockFacade]: Failed to convert value of type 'de.hybris.platform.ycommercewebservices.stock.impl.DefaultCommerceStockFacade' to required type 'de.hybris.platform.commercewebservices.core.stock.CommerceStockFacade'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'de.hybris.platform.ycommercewebservices.stock.impl.DefaultCommerceStockFacade' to required type 'de.hybris.platform.commercewebservices.core.stock.CommerceStockFacade': no matching editors or conversion strategy found","message":"Error creating bean with name 'cartEntriesController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'defaultStockValidator'

您可以尝试解决方案: 从 manifest.json 中删除模板扩展 ycommercewebservices 扩展,使用“迁移数据”模式重建和重新部署。

于 2022-02-15T09:48:15.793 回答
0

你关闭 PWA 了吗?

关闭 PWA。

一旦以 PWA 模式安装了 Spartacus,就会安装一个 service worker,它会提供 index.html 的缓存版本以及 js 文件。这会导致完全跳过 SSR。以下步骤描述了如何关闭 PWA:

检查您的应用中是否没有注册服务工作者。如果您确实找到任何服务人员,请将其删除。

在您的应用模块配置中关闭 PWA,如下所示:

 StorefrontModule.withConfig({
       backend: {
         occ: {
           baseUrl: 'https://[your_enpdoint],
         },
       },
       pwa: {
         enabled: false,
       },
 };

通过运行以下命令重建本地 Spartacus 库:

yarn build:core:lib

通过运行以下命令构建本地 Spartacus shell 应用程序:

 yarn build --prod

通过运行以下命令构建您的 shell 应用程序的 SSR 版本:

yarn build:ssr

通过运行以下命令,使用 SSR 服务器启动 Spartacus:

 yarn serve:ssr
于 2020-09-03T16:24:15.147 回答