WP-API / node-wpapi

An isomorphic JavaScript client for the WordPress REST API
http://wp-api.org/node-wpapi/
MIT License
1.68k stars 191 forks source link

Fix auto discovery #518

Open hajamie opened 4 months ago

hajamie commented 4 months ago

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!

stevenalanstark commented 3 months ago

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();