【问题标题】:gatsby-source-wordpress plugin: I cant pull data from WP into Gatsby (error with connection)gatsby-source-wordpress 插件:我无法将数据从 WP 拉入 Gatsby(连接错误)
【发布时间】:2021-01-10 17:48:35
【问题描述】:

我正在测试 Gatsby 和 WP 如何协同工作,并查看了来自官方插件文档 (Wordpress example on Github) 的示例

我使用 MAMP 进行本地托管,端口设置为 80 和 3306

我知道错误出现在 baseUrl 上的 gatsby-config.js 中,因为我尝试将其更改为虚拟网站(实时)并且问题已解决。所以我猜想在尝试从 localhost 获取 WP 数据时出现问题。这是我的 gasby-config.js 文件:

module.exports = {
  siteMetadata: {
    title: `Gatsby Default Starter`,
    description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
    author: `@gatsbyjs`,
  },
  plugins: [
    `gatsby-plugin-react-helmet`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/images`,
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-plugin-manifest`,
      options: {
        name: `gatsby-starter-default`,
        short_name: `starter`,
        start_url: `/`,
        background_color: `#663399`,
        theme_color: `#663399`,
        display: `minimal-ui`,
        icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
      },
    },
    {
      resolve: `gatsby-source-wordpress`,
      options: {
        /*
          * The base URL of the WordPress site without the trailingslash and the protocol. This is required.
          * Example : 'dev-gatbsyjswp.pantheonsite.io' or 'www.example-site.com'
          */
        baseUrl: `localhost`,
        protocol: `https`,
        hostingWPCOM: false,
        useACF: false,
        searchAndReplaceContentUrls: {
          sourceUrl: "http://localhost",
          replacementUrl: "https://localhost:8000",
         },  
      },
    },
    // this (optional) plugin enables Progressive Web App + Offline functionality
    // To learn more, visit: https://gatsby.dev/offline
    // `gatsby-plugin-offline`,
  ],
}

这是我在终端中遇到的错误:

我的尝试

  • 将 MAMP 上的端口更改为默认端口(Apache:8888,Nginx:7888,MySQL:8889)但我根本无法打开 m WP 站点(在搜索栏中输入 localhost:8888 时出现服务器错误)
  • 将 baseUrl 更改为虚拟实时网站:问题已解决,但我需要它在 localhost 上工作
  • 将协议更改为 http(而不是 https),因为我在 Stack 上阅读了类似的线程,但我仍然收到相同的错误
  • 使用 Flywheel 将我的 WP 站点迁移到临时域并改用该 baseUrl(变为 testSite123.flywheelsites.com),但同样的错误。

我觉得有点别无选择,欢迎任何想法!

【问题讨论】:

    标签: wordpress graphql gatsby gatsby-plugin


    【解决方案1】:

    您可以进行一些试验:

    • 将您的 MAMP 端口恢复或撤消为默认值,因此 baseUrl 将变为:http://localhost:8888(注意端口)。
    • 禁用 PhpMyAdmin 插件
    • 停止 SQL 服务以避免潜在的并发冲突

    【讨论】:

      猜你喜欢
      • 2019-12-10
      • 2021-03-24
      • 2021-05-08
      • 1970-01-01
      • 2019-11-14
      • 2020-08-11
      • 2018-07-21
      • 2019-12-06
      • 2021-06-11
      相关资源
      最近更新 更多