简体   繁体   English

如何使 npm start IP 地址与 php artisan serve 同步以在移动设备上使用后端功能?

[英]How can I make the npm start IP address sync with php artisan serve to use backend functionality on mobile device?

I have a React.js frontend project and Laravel backend project separated.我有一个 React.js 前端项目和 Laravel 后端项目分开。 I can access my frontend project via the local host address provided upon running npm start so I can see the frontend on a physical device of what I'm working on.我可以通过运行npm start提供的本地主机地址访问我的前端项目,这样我就可以在我正在处理的物理设备上看到前端。

However - When I try to login (backend functionality) on my physical device, it won't allow me to.但是 - 当我尝试在我的物理设备上登录(后端功能)时,它不允许我这样做。 php artisan serve 's running on my backend project and I can successfully login on the browser without any issues so my login system isn't the issue. php artisan serve正在我的后端项目上运行,我可以成功登录浏览器而没有任何问题,所以我的登录系统不是问题。

I guess my question is - how can I make it so that my physical device knows that php artisan serve 's running so I can access my web app with the localhost address given to me provided by npm start ?我想我的问题是 - 我怎样才能让我的物理设备知道php artisan serve正在运行,以便我可以使用npm start提供给我的本地主机地址访问我的网络应用程序?

In other words - how can I make 127.0.0.1:8000 ( php artisan serve ) sync up with 192.168.2.165:3000 ( npm start )?换句话说 - 我怎样才能让127.0.0.1:8000 ( php artisan serve ) 与192.168.2.165:3000 ( npm start ) 同步?

I think you want to have your app request proxied to your backend server.我认为您希望将您的应用程序请求代理到您的后端服务器。 take a look at this from Create-react-app doc : https://create-react-app.dev/docs/proxying-api-requests-in-development/从 Create-react-app doc 看看这个: https : //create-react-app.dev/docs/proxying-api-requests-in-development/

Based on your description you should add this line to your package.json for your react app :根据您的描述,您应该将此行添加到您的 react 应用程序的 package.json 中:

"proxy": "http://192.168.2.165:8000"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 php artisan serve --host 0.0.0.0 无法从同一网络上的移动设备访问 - php artisan serve --host 0.0.0.0 can't be accessed from mobile device on same network 在本地主机中使用 php artisan serve 和 npm run watch 时,url('/') 的输出为 http://localhost:8000 - In localhost when use I php artisan serve and npm run watch, output of url('/') is http://localhost:8000 如何向 IP 地址 PHP 发出 CURL 请求? - How can I make a CURL request to IP Address PHP? Laravel:php artisan服务没有开始 - Laravel: php artisan serve doesn't start 我可以在“ php artisan服务”之后立即运行查询吗 - Can i run query right after “php artisan serve” 我无法在Linux上执行PHP Artisan服务 - I can't execute php artisan serve on linux 如何在没有 php 工匠服务的情况下使用 laravel livewire? - How to use laravel livewire without php artisan serve? 如何正确对齐PHP Artisan Tinker和服务之间的数据库源 - How can I correctly align the database source between php artisan tinker and serve 如何运行 php artisan serve using.env.production? - How can I run php artisan serve using .env.production? 如何在没有 cmd 命令“php artisan serve”的情况下运行我的 Laravel 项目? - How can I run my Laravel project without cmd command "php artisan serve"?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM