Search code examples
production-environmentvaporserver-side-swift

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


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?


Solution

  • 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.