Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to fetch baseUrl #13

Open
BetaPundit opened this issue Apr 30, 2019 · 9 comments
Open

Failed to fetch baseUrl #13

BetaPundit opened this issue Apr 30, 2019 · 9 comments

Comments

@BetaPundit
Copy link

I am unable to fetch data from the WordPress url. I simply put the url of the WordPress website in the baseUrl field.
The error says:

Error: Failed to fetch baseUrl https://discover.wordpress.com/
at WordPressSource.fetchWordPressContent (Z:\My Work\Projects\sample-project\node_modules@gridsome\source-wordpress\index.js:33:13)
at
at process._tickCallback (internal/process/next_tick.js:188:7)

Here's the code in gridsome.confg.js:

module.exports = {
  siteName: 'Gridsome',
  siteDescription: 'A WordPress starter for Gridsome',
  plugins: [
    {
      use: '@gridsome/source-wordpress',
      options: {
        baseUrl: 'https://discover.wordpress.com/', // required
        typeName: 'WordPress', // GraphQL schema name (Optional)
        perPage: 3, // How many posts to load from server per request (Optional)
        concurrent: 10, // How many requests to run simultaneously (Optional)
        routes: {
          post: '/:year/:month/:day/:slug', //adds route for "post" post type (Optional)
          post_tag: '/tag/:slug' // adds route for "post_tag" post type (Optional)
        }
      }
    }
  ]
}

Everything else is the same as in the gridsome WordPress starter template.

@martifenosa
Copy link

martifenosa commented May 8, 2019

Remove the selected code in 'WordPressPost.vue' file.
Screenshot 2019-05-08 at 15 13 20

@BetaPundit
Copy link
Author

BetaPundit commented May 16, 2019

Remove the selected code in 'WordPressPost.vue' file.
Screenshot 2019-05-08 at 15 13 20

That didn't work for me!
Getting this error now:

TypeError: Cannot destructure property status of 'undefined' or 'null'.

@martifenosa
Copy link

@adityaas26 Could you solve it? Where do you use this var 'status'?
If I recall correctly the error was coming from the 'templates' folder files, if you remove those the rest should work.

@travis-r6s
Copy link
Member

@adityaas26 I tried https://discover.wordpress.com, and it doesn't look like they have the REST API enabled? Try using https://wordpress.org as your baseUrl instead.

@BetaPundit
Copy link
Author

@adityaas26 I tried https://discover.wordpress.com, and it doesn't look like they have the REST API enabled? Try using https://wordpress.org as your baseUrl instead.

Yes, @thetre97 the problem's with the wordpress.com domain which does not have the required REST API support. You can get the support by adding your own custom domain to your WordPress sites.

@lorvent
Copy link

lorvent commented Sep 10, 2019

I have tried with my own wordpress site but still it doesn't work.

i am getting same error, i tried removing code from WordpressPost.vue but still it doesn't work.

@lorvent
Copy link

lorvent commented Sep 11, 2019

after testing with many wordpress sites, i can confirm onething.

if a wp site was started long back say 5yrs back..then it throws

TypeError: Cannot destructure property `status` of 'undefined' or 'null'.
    at WordPressSource.fetch (C:\laragon\www\my-gridsome-project\node_modules\@gridsome\source-wordpress\index.js:172:40)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

but if it is a new wp installation, then it works fine.

so there must be something in old wp installations, which is root cause of the problem.

@vdilly
Copy link

vdilly commented Nov 18, 2019

I just had this issue, in my case, there was an echo() function left in one of my functions.php file, that outputed some text in my REST API response, turning it into an unvalid json.
The error was thrown during the getTaxonomies() function.

You can try to access all your REST API url to check if the datas are good, or you can just console.log your data response in each get functions of source-wordpress/index.js file.

For example, line 95 :

  async getTaxonomies(actions) {
    const { data } = await this.fetch("wp/v2/taxonomies", {}, {});
    console.log(data);
   ...

@VivianSolide
Copy link

VivianSolide commented Dec 26, 2019

@adityaas26 : I'm not able to access to this url: https://discover.wordpress.com/wp-json/wp/v2/posts
Are your permalinks properly set?

Check your permalinks options on https://discover.wordpress.com/wp-admin/options-permalink.php
The wp-json thing doesn't work with "Plain" option.

⚠️ Be aware that changing permalinks right now could lead to a lot of SEO issues.

✔️ The best option could be to try this with a fresh installation.

Hope this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants