Deploying Vapor with Heroku

Deploying a Vapor app to Heroku fails because of error: value of type 'URLSession' has no member 'data'

The async APIs for Foundation on Linux aren't available yet (they're different from the actual language concurrency features).

For a Vapor app you shouldn't really be using URLSession to make requests, it doesn't fit with how the framework works. Use Vapor's client instead (which has async APIs)

Deploying vapor on Heroku using Docker fails on $PORT

CMD ./Run serve --env production --hostname 0.0.0.0 --port $PORT

See here: https://github.com/rzeszot/cabs-swift/blob/main/Dockerfile

Deploying Vapor with heroku

A user in the Slack channel gave me insight to this problem.:

VZSG:
@animatronicgopher: experimenting on Heroku is cheap but it's pretty pointless to scale up to paid dynos just because of this. It does not make a difference – first, this error is generated by an HTTP client, so your server's certificate doesn't matter, and second, even free dynos have proper certs (and they aren't just letsencrypt certs either). What you probably found is for custom domains.

The actual problem is that the "default" HTTPClient does not care about the dyno's trusted root certificates, therefore the outgoing SSL connection cannot be verified -> error.

Also, there's an issue in GitHub that gives you a sample of how to use FoundationClient.
https://github.com/vapor/vapor/issues/699

Vapor unable to deploy to Heroku: We don't have build instructions for 5.3

Swift 5.3 doesn't appear to have been released yet, and the only Vapor buildpacks that I can find don't yet support it.

I think you're using this buildpack that uses Swift version 5.1.3 in its current documentation. Try reducing your Swift version to that (by editing your .swift-version file and committing) and redeploying.

Edit: Your new error indicates a Swift Tools version mismatch. I don't program in Swift, but it looks like this is defined by a line in your Package.swift file and that it is related to your Swift version:

The very first line of a package manifest indicates the Swift tools version required. This specifies the minimum version of Swift that the package supports. The Package description API may also change between Swift versions, so this line ensures Swift will know how to parse your manifest.

Try changing

// swift-tools-version:5.2

to

// swift-tools-version:5.1

then commit and redeploy.

I also recommend making sure that you are using the same version of Swift locally for development as you're targeting on the server.

Vapor swift Code working on localhost but after deploying at heroku all apis working fine but this one crashes

Well, your issue is right here, at the top of your method:

guard let data = req.http.body.data else {
throw req as! Error
}

Vapor's Request type doesn't conform to the Error protocol, so this typecast will crash 100% percent of the time. Instead, you should be using Vapor's built-in Abort error type, which can be used to represent any HTTP error.

guard let data = req.http.body.data else {
throw Abort(.badRequest, reason: "Missing request body")
}

Vapor app failing to deploy on Heroku: We don't have Build instructions for ’5.1.3’

Using Swift ’5.1.3’ (from .swift-version file)

Those quotes look funny. I bet your .swift-version file literally contains

’5.1.3’

Whereas it should contain

5.1.3

Get rid of the quotes, commit, and deploy again.



Related Topics



Leave a reply



Submit