我正试图让斯巴达克斯与 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 上表现得这样。