WAMP Laravel-将API请求从一个本地站点发送到另一个本地站点会混淆环境变量 [英] WAMP Laravel - Sending API requests from one local site to another mixes up environment variables

查看:65
本文介绍了WAMP Laravel-将API请求从一个本地站点发送到另一个本地站点会混淆环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个API服务,我已经开发的另一个站点将使用该服务.因此,在本地进行构建和测试时,显然我希望网站的两个本地副本都可以正常工作.但是,它似乎混淆了environment变量.

I am developing an API service that another site I've developed will be using. So locally when building and testing, obviously I want both local copies of the site to work. However, it seems to mix up the environment variables.

例如:

  • Site A具有APP_URL=http://a.local
  • Site B具有APP_URL=http://b.local
  • 我从Site A代码向http://b.local/test发送了GET请求(使用Guzzle)
  • Site B中的/test终结点只是转储dump(env('APP_URL'))
  • Site A检索到的结果是"http://a.local"
  • 预期结果:"http://b.local"
  • Site A has APP_URL=http://a.local
  • Site B has APP_URL=http://b.local
  • I send a GET Request (using Guzzle) from Site A code to http://b.local/test
  • The /test endpoing in Site B simply dumps out dump(env('APP_URL'))
  • Result retrieved by Site A is "http://a.local"
  • Expected result: "http://b.local"

因此,Site B中的代码与从Site A加载的环境变量一起运行.这是一个问题,因为Site B无法访问正确的数据库,它正在尝试使用Site A的数据库.

So the code in Site B is running with environment variables loaded from Site A. This is an issue as Site B cannot access the correct database, it's trying to use the Site A's database.

我的本​​地设置(Win10 + WAMP),PHP设置,Laravel设置是否有问题?

Is this an issue with my local setup (Win10 + WAMP), PHP settings, Laravel settings?

推荐答案

我也遇到了这个问题,并且提到了

I also encountered this issue, and it is mentioned here. The resolution for it is to run php artisan config:cache in both projects to cache configuration from .env files or patch the code from here.

这篇关于WAMP Laravel-将API请求从一个本地站点发送到另一个本地站点会混淆环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆