Vapor project swift run App serve --env production does not work

118 views Asked by At

I follow the Vapor doc and try to deploy my project. I tried to run swift run App serve --env production or .build/release/App serve --env production

[Vapor] ConsoleKit.ConsoleError(identifier: "unknownInput", reason: "Input not recognized: --env production")

And then I check the App serve -h. There is not --env.

.build/release/App serve [--hostname,-H] [--port,-p] [--bind,-b] [--unix-socket]

Begins serving the app over HTTP.

Options: hostname Set the hostname the server will run on. port Set the port the server will run on. bind Convenience for setting hostname and port together. unix-socket Set the path for the unix domain socket file the server will bind to.

Does anyone deploy a Vapor4 project on production environment successfully?

2

There are 2 answers

6
damo On BEST ANSWER

The thing is that my entry point file is "main.swift". But a file named main.swift can't have an @main attribute.

The key is you CANNOT use main.swift as the filename of the entrypoint.

0
Jack Leow On

I believe Vapor applications by default has two targets, App and Run, where Run is supposed to be the entrypoint. What happens if you run:

swift run Run serve --env production