Trying to run Swift Vapor on Bluemix - 404 Not Found: The requested route does not exist

I'm trying to figure out how to deploy a Cloudfoundry application that uses the Vapor infrastructure on IBM Bluemix.

IBM provides tools and recommendations for using its Swift server application development platform with its Kitura framework. I think that as a Cloudfoundry provider, with the appropriate Swift package, we should be able to deploy shared server-side Swift code.

Finally, while studying CF bits, I got to the point where with CLI CloudFoundry:

  • I am connecting to the Bluemix API endpoint (api.eu-gb.bluemix.net)
  • Input ok (after extending the timeout env. Var CF_DIAL_TIMEOUT to 20)
  • Creating a "cf push". He creates the application, downloads and compiles everything.
  • The application state is running.

But when I load the page ( https://sommobilitatcore.eu-gb.mybluemix.net/ ), I get:

404 Not Found: Requested route ('sommobilitatcore.eu-gb.mybluemix.net') does not exist. 

Can someone help me with this? Thanks!

In some context:

. manifest.yml:

 applications: - path: . memory: 256M instances: 1 name: SomMobilitatCore disk_quota: 1024M buildpack: https://github.com/IBM-Swift/swift-buildpack.git 

Profile

 web: App 

(main.swift is in Source / App /)

No port is configured in the Vapor configuration files, then Vapor tries to listen on port 80:

 import Vapor import HTTP let drop = Droplet() let _ = drop.config["app", "key"]?.string ?? "" drop.get("/") { request in return try drop.view.make("welcome.html") } (...) let port = drop.config["app", "port"]?.int ?? 80 // Print what link to visit for default port drop.serve() 

UPDATE:

Finally, run it without Procfile, manifest.yml

 - path: . instances: 1 memory: 256M disk_quota: 1024M name: SomMobilitat4 command: App --env=production --workdir="./" buildpack: swift_buildpack 

And / Config / production / servers.json:

 { "production": { "port": "$PORT" } } 

I do not specify a port variable in the main.swift file. With the updated version of Vapor:

 import Vapor import HTTP let drop = Droplet() drop.get("/") { request in return "hello vapor in bluemix cloudfoundry" } drop.run() 

If you're new to Cloudfoundry or IBM Bluemix, this is the way to work:

  • You register with a Cloudfoundry provider (ex: bluemix)
  • You have a Vapor project locally.
  • Add to this a .cfignore file with this short line: Packages / so that packages are not uploaded to the server.
  • Add to it the mentioned manifest.yml file.
  • Download and install CLI Cloudfoundry: https://docs.cloudfoundry.org/cf-cli/

    With CLI:

  • cf api https://api.eu-gb.bluemix.net

  • cf login
  • cf push
+6
source share
2 answers

To launch the Vapor app on Bluemix:

  • Add the Config directory with servers.json (use these names). servers.json should contain the following:
      {
             "myserver": {
                 "port": "$ PORT"
             }
         }
      

It will instruct Vapor to start a server named myserver on the port taken from the $PORT environment variable used by Bluemix.

  1. In your Procfile add the --workDir=. option --workDir=. , so it will contain:

      web: App --workDir =.
    

    It will instruct Vapor to look for the Config directory in the current directory at runtime.

+1
source

I am not very familiar with Swift and Vapor, but for any casting application you must use the port from the environment variable VCAP_APPLICATION.

Bluemix has created a useful package for Swift, which you can get with this port number.

In the Package.swift file, add the following line:

 .Package(url: "https://github.com/IBM-Swift/Swift-cfenv.git", majorVersion: 1, minor: 7) 

Then you can use something like this to get the correct port number to run your application:

 import CloudFoundryEnv ... let appEnv: AppEnv appEnv = try CloudFoundryEnv.getAppEnv() let port = appEnv.port 

You can check the Bluemix Swift startup code for more details:

https://github.com/IBM-Bluemix/Kitura-Starter

0
source

All Articles