如何以自定义主机名启动独立的WireMock?

huangapple go评论50阅读模式
英文:

How to start wiremock standalone with custom hostname?

问题

例如,我想要以主机名“my.abc.com”和端口9999启动独立的Wiremock。在哪里可以配置这个?或者主机名的正确命令行选项是什么?
提前非常感谢。

英文:

For example, I want to start wiremock standalone with hostname "my.abc.com" with port 9999. Where can I config that? Or what is the right command line options for hostname?
Thanks a lot in advance.

答案1

得分: 3

主机名由DNS或您的主机文件确定,而不是由WireMock本身确定。

如果您想在本地运行一切,但主机名不是localhost,您可以编辑您的主机文件并添加一行,如下所示:

127.0.0.1 api.mydomain.com

然后,您可以访问本地运行的WireMock服务器,例如:http://api.mydomain.com:9999/

正如agoff所指出的,如果您想使用Java DSL与该实例交互,您需要进行配置:

WireMock.configureFor("api.mydomain.com", 9999);

主机文件可以在以下位置找到:
Windows - c:\Windows\System32\Drivers\etc\hosts
Mac - /private/etc/hosts
*nix - /etc/hosts

英文:

The hostname is determined by DNS or your host file, rather than WireMock itself.

If you want to run everything locally but with a hostname other than localhost you can edit your hosts file and add a line like:

127.0.0.1 api.mydomain.com

Then you can hit a locally running WireMock server on e.g. http://api.mydomain.com:9999/

As agoff points out, if you want to use the Java DSL against the instance you need to configure it:

WireMock.configureFor("api.mydomain.com", 9999);

The host file can be found in the following places:
Windows - c:\Windows\System32\Drivers\etc\hosts

Mac - /private/etc/hosts

*nix - /etc/hosts

huangapple
  • 本文由 发表于 2023年2月8日 19:40:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75385279.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定