Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hosting Vapor Swift App on Google Cloud Platform

I have set up an Ubuntu instance on Google Cloud Platform and installed Swift-3 and Vapor on it. Then I tried to build the Vapor app with vapor build command and it succeeded. Then I run vapor run on the application folder, it successfully initiate the server and the console says that the service is available on local host, 0.0.0.0:8080.

But when I enter the static ip of my VM in the browser window I am not able to see the vapor page I am supposed to. Instead I am getting a connection refused error.

like image 901
Selvin Avatar asked Feb 07 '23 15:02

Selvin


1 Answers

Port 80 is the default port for HTTP (non TLS) connections. It's likely that since Vapor is connecting to port 8080, it is being blocked by a firewall.

Try doing vapor run --port=80 --env=production (you may need sudo)

This will set the port to 80 and will also set the environment to production to prevent any debug logging that could slow your application down.

EDIT:

Port configuration is done through the Config/servers.json file now.

{
    "default": {
        "port": 8080,
        "host": "localhost",
        "securityLayer": "none"
    }
}

However, you can still override through the command line interface with an updated command.

--config:servers.default.port=8080

like image 167
tanner0101 Avatar answered Feb 13 '23 07:02

tanner0101