Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing hostname and port with Vapor 3

The Config/server.json file doesn't seem to be read by Vapor 3, and as such I can't configure the hostname and port that a Vapor 3 app binds to.

Does Vapor 3 have a different method for this?

like image 754
Adam Young Avatar asked Jan 25 '18 19:01

Adam Young


2 Answers

Official Solution (as sanctioned by the maintainers)

You can use NIOServerConfig.

let serverConfiure = NIOServerConfig.default(hostname: "0.0.0.0", port: 9090)
services.register(serverConfiure)

Vapor version is 3.0.3

like image 150
Passaction Avatar answered Oct 23 '22 12:10

Passaction


Currently, you can set the port and hostname when running your server:

swift run Run --hostname 0.0.0.0 --port 9000

There appears to be struct-based configuration for EngineServer but I don’t think it is configurable at run time just yet. The last time the Vapor developer answered this question (on their Slack) the command-line argument method was the suggested one.

like image 23
tobygriffin Avatar answered Oct 23 '22 13:10

tobygriffin