Ada*_*ung 9 docker swift vapor
Vapor 3似乎没有读取Config/server.json文件,因此我无法配置Vapor 3应用程序绑定的主机名和端口.
Vapor 3有不同的方法吗?
小智 21
您可以使用NIOServerConfig.
let serverConfiure = NIOServerConfig.default(hostname: "0.0.0.0", port: 9090)
services.register(serverConfiure)
Run Code Online (Sandbox Code Playgroud)
蒸汽版本是3.0.3
yas*_*bas 10
在蒸气 4
app.http.server.configuration.hostname = "127.0.0.1"
app.http.server.configuration.port = 8000
Run Code Online (Sandbox Code Playgroud)
在蒸气 3
services.register(NIOServerConfig.default(hostname: "127.0.0.1", port: 8000))
Run Code Online (Sandbox Code Playgroud)
确保使用的是Vapor 3版本,然后使用以下版本:
vapor run --hostname=0.0.0.0 --port=8080
Run Code Online (Sandbox Code Playgroud)
如果您未 =在参数后添加,则会收到以下投诉:
CommandError: Unknown command 8080
Run Code Online (Sandbox Code Playgroud)
如果您按照我上面的建议进行操作,您将收到:
[Deprecated] --option=value syntax is deprecated.
Run Code Online (Sandbox Code Playgroud)
请改用--option值(不带=),但该命令将运行并正常运行。
没有=参数,我无法找到一种运行此命令的方法。
我的 0.02 美元
import Vapor
/// Called before your application initializes.
///
/// [Learn More ?](https://docs.vapor.codes/3.0/getting-started/structure/#configureswift)
public func configure(
_ config: inout Config,
_ env: inout Environment,
_ services: inout Services
) throws {
if env == .development {
services.register(Server.self) { container -> EngineServer in
var serverConfig = try container.make() as EngineServerConfig
serverConfig.port = 8989
serverConfig.hostname = "192.168.31.215"
let server = EngineServer(
config: serverConfig,
container: container
)
return server
}
}
//Other configure code
}
Run Code Online (Sandbox Code Playgroud)
它在 Vapor 3.0.0 RC 2.4.1 上完美运行
| 归档时间: |
|
| 查看次数: |
3987 次 |
| 最近记录: |