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

Failed to Enable Auto-Discovery #508

Open emiltsang opened 2 years ago

emiltsang commented 2 years ago

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