Server Side Swift with Vapor - Part 2: Hello World | Ray Wenderlich

Learn how to create your first Vapor app by installing the Vapor toolbox and building your first routes.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4493-server-side-swift-with-vapor/lessons/2

Unfortunately vapor3 may be a bit buggy. I tried vapor Xcode and get the following error:
error: unknown option --enable-prefetching; use --help to list available options
Error: Could not generate Xcode project: error: unknown option --enable-prefetching; use --help to list available options

@fordee ah you’re running 4.1 in the command line as well. There is an update to the toolbox being pushed through now so you should be able to run brew upgrade vapor/tap/vapor when it is pushed out (which I imagine should be in the next couple of hours) but for now run swift package generate-xcodeproj and it will do the same thing and should get you going

Thanks. I also just found that out via the codevapor slack channel. I would recommend any other followers of this tutorial to subscribe to if they have problems (as you mention). Vapor3 is still beta.

The fix to the toolbox should be in Homebrew now! Yep we have notes on all the videos I believe to point people to the Slack channel if they get stuck. I think that should be one of the only few issues

My Xcode is crashing when trying to build the Hello World Vapor app.

@vakas Which stage is it crashing (i.e. have you written any code yet)?

If you do a build (CMD+B) without running does it still crash?

(CMD+B) is successful. But when I run it, the xcode closes itself. Yeah without writing anything it is crashing.

Ok that’s good! Unfortunately there is a bug in Xcode where if there is an unhandled error the whole of Xcode crashes… :unamused:

So it means there is a bug somewhere, which if you have just done vapor new HelloWorld --branch=beta and vapor xcode and built is weird :thinking:

Easiest way to catch this is to wrap your main.swift code in a do/catch and see what the error being printed out is. See https://github.com/vapor/api-template/pull/45/files#diff-cfe0f72e82b19138a2788e241bc38f20 to see how to do this

Really appreciate your prompt response. Let me try.

 [Possible causes: The address that binding was attempted on does not refer to your machine.] [Suggested fixes: Bind to `0.0.0.0` or to your machine's IP address]
Program ended with exit code: 0

Huh that is bizarre - it’s like you machine is missing it’s loopback interface :thinking: If you run ifconfig in terminal do you see the 127.0.0.1 IP bound to lo0? Just to check are you running on a standard Mac?

Yes running on a standard Mac and 127.0.0.1 is bound to lo0

Final question - does 127.0.0.1 point to localhost in /etc/hosts?

However, you can change the port and hostname it binds to. In configure.swift add:

services.register { _ in 
  EngineServerConfig.detect(hostname: "127.0.0.1", port: 8080) 
}

Or change the address to 0.0.0.0 to accept requests from all IP address. You can try changing the port as well in case there is something listening on that port, but that should throw a different error

2 Likes

Finally this worked. :+1:

1 Like

Hi Tim
I really appreciate this tutorial, explanations are crystal-clear, and the subject itself is very interesting for iOS developers.

I installed the newest Swift 4.1 toolchain, selected it in Xcode, and then generated the project. But when I run vapor xcode, I got the following error:

Generating Xcode Project [Failed]
error: the package https://github.com/vapor/sockets.git @ 3.0.0-beta.1 contains revisioned dependencies:
https://github.com/vapor/async.git @ beta
https://github.com/vapor/core.git @ beta
error: product dependency ‘FluentSQLite’ not found
error: product dependency ‘Vapor’ not found

Do you have a clue why this is happening ?

Thanks
Fred

Hi Fred,
Beta problems! Can you delete the project directory and try again? Should be fixed, if not I’ll kick the Vapor team :smile:

Tim

That worked! I deleted everything and tried anew, and now my xcode project is perfect. Thanks for your quick answer!

1 Like