当此服务器的 IP 不同于本地主机时,如何在 XAMPP 中调用我的 API?

How to call my API in XAMPP when this server has an IP different than localhost?

我在 macOS Catalina 中安装了新的 XAMPP 7.4,window 与以前有很大不同。我按下 Mount,它就会运行。但是我有 Angularjs 项目在 htdocs 中调用 API Rest Laravel 项目,但不起作用,因为它调用本地主机或计算机的本地 IP,但我不现在知道 XAMPP 是如何工作的。

XAMPP 在 htdocs 所在的位置创建一个新 IP,我访问该文件夹时会抛出 IP,但我的 Angularjs 项目无法访问,因为他们不知道 IP,只能调用127.0.0.1.

如何配置 XAMPP 以使用本地主机或如何配置 Angularjs 以调用该 IP 而不影响我的生产服务器?

谢谢!

免责声明:我以前没有这样做过,我的回答是基于我的 angularjs 经验和简短的搜索。

尝试一个全新的项目

在这篇文章(您可能已经看过并尝试过)中:https://kode-blog.io/angularjs-install-and-configure 有一个非常相关的部分,即第 1 步:"You can directly create the folder angular-js in drive C:\xampp\htdocs"。我知道您的问题只是隐约相关,但您可以尝试按照本文的步骤使用一个全新的项目

XAMPP 至 local/virtual 主机

如果我理解正确的话,您正在寻找一种方法来修改 XAMPP/AngularJS 服务于同一 IP。让我们先尝试将 XAMPP 设置为本地主机: Setting up a virtual host on XAMPP on Mac or How to set xampp open localhost:8080 instead of just localhost and also more detailed, step-by-step ones: https://jonathannicol.com/blog/2012/03/11/configuring-virtualhosts-in-xampp-on-mac/

向特定主机提供 AngularJS

AngularJS 比 Angular 2+ 灵活得多() when it comes to serving a host. You could try using http-server and node.js (first answer here: 但也查看其他答案,那里有一些额外有用的信息)

额外位

你的尝试似乎是绝对可行的,也有人做过( or https://www.quora.com/Can-we-use-AngularJS-in-XAMPP),但这不是最常见的事情。

我知道这个答案不会直接给你一个易于实现的单行代码,但我希望它至少能开始讨论并产生更有用的东西。

要使用像 localhost:8080 这样的状态 IP,您必须转到 XAMPP 中的“网络”选项卡,然后在 localhost:8080 选项上按“启用”。我很惭愧花了太长时间才找到这个。谢谢。