magento/module-upward-connector

Magento模块,用于将所有前端请求路由通过UPWARD-PHP。

安装次数: 270,852

依赖项: 1

建议者: 0

安全: 0

星标: 24

关注者: 15

分支: 27

开放问题: 19

类型:magento2-module

2.0.4 2024-03-21 06:35 UTC

README

Magento 2 UPWARD连接器是一个模块,用于将请求路由到UPWARD-PHP。此模块用PWA Studio店面应用程序替换了默认的Magento前端主题。

Magento Commerce Cloud中的PWA Studio店面部署使用此模块以将Magento和店面代码保持在同一服务器上。

安装

Magento 2 UPWARD连接器模块是官方PWA Studio文档中Magento Cloud部署步骤的一部分。

配置

Magento 2 UPWARD连接器有额外的设置,可以在管理员区域中的以下位置配置:

商店 > 配置 > 一般 > 网络 > UPWARD PWA配置.

一般配置

这些是UPWARD过程的配置。

UPWARD配置文件

此配置是UPWARD-PHP服务器UPWARD配置文件的位置。

此模块向env.php添加了一个新的指令,以安全地设置upward.yaml文件的路径。

    // ...
    'downloadable_domains' => [
        // ...
    ],
    # New configuration point
    'pwa_path' => [
        'default' => [
            'default' => '/var/www/html/pwa/dist/upward.yml'
        ],
        'website' => [
            '<website_code>' => '/var/www/html/anotherpwa/dist/upward.yml' # Can point a website to a different installation
        ],
        'store' => [
            '<store_code>' => '' # Blank string (or false) to serve default Magento storefront
        ]
    ]

为了便于使用,此模块提供了一个新的命令来设置路径

# Set the default scope to an empty string (will serve base Magento store front)
bin/magento pwa:upward:set

# Set the website with code <website_code> to /var/www/html/pwa/dist/upward.yml
bin/magento pwa:upward:set --path /var/www/html/pwa/dist/upward.yml --scopeType website --scopeCode <website_code>

# Set the website with code <website_code> to an empty string (will serve base Magento store front)
bin/magento pwa:upward:set --scopeType website --scopeCode <website_code>

# Set the website with code <store_code> to /var/www/html/pwa/dist/upward.yml
bin/magento pwa:upward:set --path /var/www/html/pwa/dist/upward.yml --scopeType store --scopeCode <store_code>

您可以使用bin/magento store:listbin/magento store:website:list轻松获取用于配置的商店/网站代码。

您可以使用此配置的值的相对路径或绝对路径。

  • 相对:pwa/dist/upward.yml
  • 绝对:/var/www/html/pwa/dist/upward.yml

如果您以前使用config:set命令或环境变量配置了UPWARD yaml路径,它将继续按上述示例作为后备使用,只要没有设置默认值。

配置的工作方式与正常商店配置的工作方式相同。它从商店视图 > 网站到全局(默认)回退,首先尝试服务更具体的可用范围。

前端名称允许列表

此配置允许您指定要转发到默认Magento主题的行分隔的路线列表。

示例

contact
privacy-policy-cookie-restriction-mode

在此示例中,当访客导航到<Magento商店URL>/contact<Magento商店URL>/privacy-policy-cookie-restriction-mode时,他们将看到由Magento渲染的页面,而不是店面应用程序。

Prerender.io配置

upward-connector模块中的Prerender.io支持允许您的网站将预渲染的静态HTML发送到搜索引擎蜘蛛。

一个中间件层检查每个请求是否来自爬虫,如果允许,则将其发送到预渲染服务。这些配置条目允许您配置要将哪些页面发送到Prerender.io以提供该页面的静态HTML版本。如果页面未配置为预渲染,则请求将继续使用正常的服务器路由。

测试预渲染页面

要查看爬虫如何查看预渲染的页面,请将浏览器用户代理设置为Googlebot并访问您的URL。您也可以在命令行上运行此操作,并将示例URL更改为您的店面URL

curl -A Googlebot https://www.example.com/ > page.html

要配置本地Prerender.io以进行测试,请参阅https://docs.prerender.io/test-it/

处理部分渲染的页面问题

无法确定PWA页面何时完全加载。对于预渲染,可以在设置window.prerenderReady标志之前,强制预渲染等待一个预定义的超时时间。

将以下内容添加到运行时脚本中

window.prerenderReady = false;
setTimeout(function () {
  window.prerenderReady = true;
}, 1000 * 15);

更多信息,请参阅https://docs.prerender.io/test-it/

服务工作者注意事项

避免在PWA Studio店面和Magento 2管理后台之间共享相同的域名。这会导致当你在浏览器中同时打开店面和管理标签页时,店面服务工作者拦截后台请求。如果你无法避免共享域名,每次只访问一个服务,或者为每个服务使用一个私密浏览会话。