【问题标题】:Gatsby-Source-Wordpress configurationGatsby-Source-Wordpress 配置
【发布时间】:2019-11-14 14:07:13
【问题描述】:

盖茨比-源-WordPress 盖茨比开发 返回: "服务器响应为 "404 Not Found"

运行 Gatsby 默认启动器 在 localhost 上全新安装 wordpress。

wordpress 在这里:localhost/freshinstall 我在这里看到 json 数据:localhost/freshinstall/wp-json/ wordpress 中的永久链接设置为:帖子名称

gatsby-source-wordpress 是 gatsby 中唯一安装的插件:

   {
      resolve: `gatsby-source-wordpress`,
      options: {
        // your wordpress source
        baseUrl: `localhost/freshinstall`,
        protocol: `http`,
        hostingWPCOM: false,
        useACF: true
      }
    },

希望能够访问 wordPress 中的信息。

以下是我看到的:

my-default-starter dk$ gatsby develop
success open and validate gatsby-configs - 0.067 s
success load plugins - 42.771 s
success onPreInit - 0.034 s
success initialize cache - 0.061 s
success copy gatsby files - 2.423 s
success onPreBootstrap - 0.052 s

Path: /freshinstall/wp-json
The server response was "404 Not Found"

 ERROR 

Plugin gatsby-source-wordpress returned an error Cannot read property 'data' of undefined



  TypeError: Cannot read property 'data' of undefined

  - fetch.js:134 fetch
    [my-default-starter]/[gatsby-source-wordpress]/fetch.js:134:21

  - next_tick.js:68 process._tickCallback
    internal/process/next_tick.js:68:7


warn The gatsby-source-wordpress plugin has generated no Gatsby nodes. Do you need it?
success source and transform nodes - 1.840 s
success building schema - 1.270 s
success createPages - 0.007 s
success createPagesStatefully - 1.266 s
success onPreExtractQueries - 0.089 s
success update schema - 0.078 s
success extract queries from components - 25.299 s
success write out requires - 0.165 s
success write out redirect data - 0.044 s
success Build manifest and related icons - 0.402 s
success onPostBootstrap - 0.458 s
⠀
info bootstrap finished - 269.881 s
⠀
success Generating image thumbnails — 6/6 - 2.762 s
success run static queries - 3.311 s — 3/3 0.91 queries/second
success run page queries - 0.077 s — 5/5 93.18 queries/second
 DONE  Compiled successfully in 105741ms                                                                                                  3:25:50 PM
⠀
You can now view gatsby-starter-default in the browser.
⠀
  http://localhost:8000/
⠀
View GraphiQL, an in-browser IDE, to explore your site's data and schema
⠀
  http://localhost:8000/___graphql
⠀
Note that the development build is not optimized.
To create a production build, use npm run build
⠀
ℹ 「wdm」:
ℹ 「wdm」: Compiled successfully.

【问题讨论】:

标签: wordpress gatsby


【解决方案1】:

原来我自己的机器坏了。

解决这个问题需要很长时间,最终解决问题的是改变机器上 apache 的设置方式。链接 localhost/domain 并不是字面上的意思。我破坏了 apache,破坏了 mysql,然后修复了两者,然后不得不更改端口,最后它现在像这样工作:

本地主机:8888/域

在那之后,Gatsby-Source-WordPress 中的一切都正常工作了。

【讨论】:

    【解决方案2】:

    我偶然发现了同样的问题,以下是我所做的事情:

    • 我的 MAMP 设置的默认端口为 80。可以通过 http://localhost 访问本地 Wordpress。我将 MAMP 端口恢复为默认值,因此本地 url 变为 http://localhost:8888/如果应用了您的域名

    • 我强制停止了在我的 Mac 上同时运行的 sqld。

    • 我去了 phpMyAdmin 并禁用了所有活动的插件。

    • 我去了 wp-admin 并将永久链接重置为 帖子名称。这已经被设置为 post name,但仍然单击 Save 按钮来提交更改。

    回想起来,我不知道罪魁祸首是什么,但希望这对某人有所帮助。

    【讨论】:

      【解决方案3】:

      嘿,你的配置应该是这样的,但如果不让我知道,我会修复 :)。

      {
            resolve: `gatsby-source-wordpress`,
            options: {
              baseUrl: process.env.API_URL,
      
              protocol: process.env.API_PROTOCOL,
      
              hostingWPCOM: false,
      
              useACF: true,
      
              includedRoutes: [
                "**/categories",
                "**/posts",
                "**/pages",
                "**/media",
                "**/tags",
                "**/taxonomies",
                "**/users",
                "**/menus",
                "**/portfolio",
                "**/services",
                "**/qualifications",
                "**/gallery",
                "**/logo",
                "**/location",
              ],
            },
          },
      }
      

      【讨论】:

        猜你喜欢
        • 2019-12-10
        • 2018-07-21
        • 2018-09-03
        • 2021-03-21
        • 2021-01-13
        • 2021-03-24
        • 2020-09-21
        • 2021-01-10
        • 2020-03-20
        相关资源
        最近更新 更多