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 01 Answer
Reset to default 0Just 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
版权声明:本文标题:json - WordPress REST API not working on localhost 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736292838a1929019.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论