我在 WSL2 的端口 8080 上启动并运行了 Express API 服务器。我尝试127.0.0.1从运行 Postman 和浏览器的 Windows 主机访问端点,但无法访问 API。更改127.0.0.1为localhost有效,但我想知道为什么不起作用127.0.0.1。也许 Window 的主机文件与此路由/转发冲突?
这是 Windows 主机文件:
#
127.0.0.1 localhost
::1 localhost
# Added by Docker Desktop
192.168.0.14 host.docker.internal
192.168.0.14 gateway.docker.internal
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section
Run Code Online (Sandbox Code Playgroud)
这是 WSL2 主机文件:
# This file was automatically generated by WSL. To stop automatic generation of this file, add …Run Code Online (Sandbox Code Playgroud) 虽然不是必需的,但枚举键通常全部以大写字母声明。但是,枚举值可以与键本身不同。
declare enum MyEnum {
PRODUCTION = "production",
DEVELOPMENT = "development",
SANDBOX = "sandbox"
}
Run Code Online (Sandbox Code Playgroud)
如果我要使用与我的枚举值匹配的外部字符串值来索引我的枚举,它将不起作用,因为键与值不同:
const lowercase = "production";
const UPPERCASE = "PRODUCTION";
const bad = MyEnum[lowercase]; // does not work
const good = MyEnum[UPPERCASE]; // works
Run Code Online (Sandbox Code Playgroud)
我想使用枚举值作为索引枚举的方式。我是否被迫始终匹配相同的枚举值和枚举键才能动态索引枚举,或者我是否必须使用一些字符串值操作来确保键与值匹配?
api ×1
enums ×1
javascript ×1
localhost ×1
typescript ×1
windows ×1
windows-subsystem-for-linux ×1
wsl-2 ×1