admin管理员组

文章数量:1122846

I have a WordPress site running WordPress 5.9.3 that is using a React-based theme, which uses the REST API (v1), to retrieve content and menus from the standard WordPress CMS back-end.

However, when trying to install it locally, I can't get the API to work and retrieve the needed data.

I'm using a Docker environment based off this repo:

Since the theme uses React and the REST API to get the site content, trying to view the site gets stuck on the loading screen.

These are the console errors:

GET http://localhost:3000/wp-json/{REDACTED_API_NAME}/v1/site net::ERR_CONNECTION_REFUSED
GET http://localhost:3000/wp-json/{REDACTED_API_NAME}/v1/menus?location=main-menu net::ERR_CONNECTION_REFUSED
GET http://localhost:3000/wp-json/{REDACTED_API_NAME}/v1/menus?location=footer-menu net::ERR_CONNECTION_REFUSED

And here is a stack trace of the first one, for reference if it helps:

(anonymous) @   VM382:1
fetchSiteInformation    @   bundle.ea81906….js:2499
fetchInitialContent @   bundle.ea81906….js:2535
(anonymous) @   bundle.ea81906….js:5653
(anonymous) @   bundle.ea81906….js:13750
(anonymous) @   bundle.ea81906….js:12811
componentWillMount  @   bundle.ea81906….js:18846
Ng  @   bundle.ea81906….js:12158
fi  @   bundle.ea81906….js:12197
Rj  @   bundle.ea81906….js:12284
Qj  @   bundle.ea81906….js:12267
Kj  @   bundle.ea81906….js:12267
yj  @   bundle.ea81906….js:12260
Ig  @   bundle.ea81906….js:12251
bk  @   bundle.ea81906….js:12302
(anonymous) @   bundle.ea81906….js:12305
Nj  @   bundle.ea81906….js:12261
ik  @   bundle.ea81906….js:12305
exports.render  @   bundle.ea81906….js:12311
(anonymous) @   bundle.ea81906….js:11350
__webpack_require__ @   bundle.ea81906….js:20
(anonymous) @   bundle.ea81906….js:63
(anonymous) @   bundle.ea81906….js:66

webpack itself compiles with warnings.

The webpack-dev-server is running off port 8081, and phpmyadmin is running off 8080.

I tried to switch the webpack server to use port 3000 instead (to match what the API is calling), but that didn't help.

I can log into WP admin and am having no issues on that side. All content and plugins are present.

This is not an issue on production or UAT environments, nor is it occurring with others on their own local machine.

I'm running Mac Monterey with the Apple M1 chip.

I have a WordPress site running WordPress 5.9.3 that is using a React-based theme, which uses the REST API (v1), to retrieve content and menus from the standard WordPress CMS back-end.

However, when trying to install it locally, I can't get the API to work and retrieve the needed data.

I'm using a Docker environment based off this repo: https://github.com/kassambara/wordpress-docker-compose

Since the theme uses React and the REST API to get the site content, trying to view the site gets stuck on the loading screen.

These are the console errors:

GET http://localhost:3000/wp-json/{REDACTED_API_NAME}/v1/site net::ERR_CONNECTION_REFUSED
GET http://localhost:3000/wp-json/{REDACTED_API_NAME}/v1/menus?location=main-menu net::ERR_CONNECTION_REFUSED
GET http://localhost:3000/wp-json/{REDACTED_API_NAME}/v1/menus?location=footer-menu net::ERR_CONNECTION_REFUSED

And here is a stack trace of the first one, for reference if it helps:

(anonymous) @   VM382:1
fetchSiteInformation    @   bundle.ea81906….js:2499
fetchInitialContent @   bundle.ea81906….js:2535
(anonymous) @   bundle.ea81906….js:5653
(anonymous) @   bundle.ea81906….js:13750
(anonymous) @   bundle.ea81906….js:12811
componentWillMount  @   bundle.ea81906….js:18846
Ng  @   bundle.ea81906….js:12158
fi  @   bundle.ea81906….js:12197
Rj  @   bundle.ea81906….js:12284
Qj  @   bundle.ea81906….js:12267
Kj  @   bundle.ea81906….js:12267
yj  @   bundle.ea81906….js:12260
Ig  @   bundle.ea81906….js:12251
bk  @   bundle.ea81906….js:12302
(anonymous) @   bundle.ea81906….js:12305
Nj  @   bundle.ea81906….js:12261
ik  @   bundle.ea81906….js:12305
exports.render  @   bundle.ea81906….js:12311
(anonymous) @   bundle.ea81906….js:11350
__webpack_require__ @   bundle.ea81906….js:20
(anonymous) @   bundle.ea81906….js:63
(anonymous) @   bundle.ea81906….js:66

webpack itself compiles with warnings.

The webpack-dev-server is running off port 8081, and phpmyadmin is running off 8080.

I tried to switch the webpack server to use port 3000 instead (to match what the API is calling), but that didn't help.

I can log into WP admin and am having no issues on that side. All content and plugins are present.

This is not an issue on production or UAT environments, nor is it occurring with others on their own local machine.

I'm running Mac Monterey with the Apple M1 chip.

Share Improve this question edited Apr 7, 2022 at 15:02 Yami Medina asked Apr 7, 2022 at 14:56 Yami MedinaYami Medina 1311 silver badge6 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0

Just had this same problem and checked other threads and this really worked: in the AdminPanal => Settings -> Permalinks -> change from 'default' to 'Post name' then Save Permalinks and reload your api url and it should be working now.

本文标签: jsonWordPress REST API not working on localhost