node-wpapi
node-wpapi copied to clipboard
Failed to Enable Auto-Discovery
I was trying to enable the Auto-Discovery with
var apiPromise = WPAPI.discover( 'http://my-site.com' );.
I have added the send_header function to functions.php under the theme folder.
add_action( 'send_headers', function() {
if ( ! did_action('rest_api_init') && $_SERVER['REQUEST_METHOD'] == 'HEAD' ) {
header( 'Access-Control-Allow-Origin: *' );
header( 'Access-Control-Expose-Headers: Link' );
header( 'Access-Control-Allow-Methods: HEAD' );
}
} );
However, I got the following errors
ERROR No header link found with rel="https://api.w.org/"
at locateAPIRootHeader (node_modules/wpapi/lib/autodiscovery.js:32:8)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
ERROR Autodiscovery failed
at node_modules/wpapi/wpapi.js:465:10
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
Can I check that the send_header function is placed in the correct file?
Also, where should I place the plugin.php file for rest-filter plugin?
rest-filter plugin