Tomo.Log()


[Vapor3] How to change port number

[09/12, 2018]

日本語 / English

You need to change the port number when You want to boot several vapor-apps. There are some ways to change it.

The Way 1: Use command option "-p" or "--port"

There are options "-p" and "--port" when the app is booted. But "vapor run -p" doesn't work so use ".build/debug/Run" like this below.

For debug build.

.build/debug/Run  -p 8080

For release build.

.build/release/Run  -p 8080

The Way 2: Modify the "NIOServerConfig"

Modify the "NIOServerConfig" in "configure" like this to change the port and so on. I'm not sure this is a proper way to do. But it works.

public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {

let ioServerConfig : NIOServerConfig = NIOServerConfig(
        hostname: "127.0.0.1",
        port:  8080,
        backlog:  256,
        workerCount:  ProcessInfo.processInfo.activeProcessorCount,
        maxBodySize:  1_000_000,
        reuseAddress:  true,
        tcpNoDelay:  true
 )
    
 services.register(ioServerConfig)

     //Other settings..
}

If use command option and modify the "NIOServerConfig"?

I've tried and it seems "command option" has priority.