node-wpapi icon indicating copy to clipboard operation
node-wpapi copied to clipboard

Fix auto discovery

Open hajamie opened this issue 1 year ago • 2 comments

There are a couple of open issues around this. I was trying to use auto discovery and it didn't work.
https://github.com/WP-API/node-wpapi/issues/504 https://github.com/WP-API/node-wpapi/issues/503

This seems to fix the issue. See https://stackoverflow.com/questions/546433/regular-expression-to-match-balanced-parentheses

I don't know how the testing or anything works. This is the first time I've made a contribution to a project, so apologies in advance!

hajamie avatar May 08 '24 16:05 hajamie

it worked for me. A much simpler regex with fewer wildcards.

I have issues with settings and themes, but I don't need these for my project

Also, I had to provide my own transport

My usage ( node ESM JS ):

import WPAPI from "wpapi";
import axios from "axios";

const API = new WPAPI( {
  endpoint: 'https://wordpress-acme.com/wp-json/',
  transport: axios
} );
const WP = await API.bootstrap();
const posts = await WP.posts();
const pages = await WP.pages();
const media = await WP.media();

stevenalanstark avatar Jun 29 '24 06:06 stevenalanstark

I'm running into this issue as well with v1.2.2 and seems the CI is complaining about something preventing this from being merged... given it's been a year it may be that this branch is out of sync with upstream.

bmcminn avatar Jun 10 '25 21:06 bmcminn