在MacOS上创建一个 hello Vapor 后台项目

Posted 无尽的期待

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在MacOS上创建一个 hello Vapor 后台项目相关的知识,希望对你有一定的参考价值。

1. 查看当前环境

:~ user$ eval "$(curl -sL check.vapor.sh)"

正常情况

?  Xcode 9 is compatible with Vapor 2.
?  Xcode 9 is compatible with Vapor 3.
?  Swift 4.1 is compatible with Vapor 2.
?  Swift 4.1 is compatible with Vapor 3.

碰到的情况

?  Xcode 9 is compatible with Vapor 2.
?  Xcode 9 is compatible with Vapor 3.
2018-06-08 10:54:13.808 xcodebuild[91618:4860941] [MT] PluginLoading: Required plug-in compatibility UUID 426A087B-D3AA-431A-AFDF-F135EC00DE1C for plug-in at path ‘~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/XAlign.xcplugin‘ not present in DVTPlugInCompatibilityUUIDs
2018-06-08 10:54:13.809 xcodebuild[91618:4860941] [MT] PluginLoading: Required plug-in compatibility UUID 426A087B-D3AA-431A-AFDF-F135EC00DE1C for plug-in at path ‘~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/VVDocumenter-Xcode.xcplugin‘ not present in DVTPlugInCompatibilityUUIDs
?  Swift 4.1 is compatible with Vapor 2.
?  Swift 4.1 is compatible with Vapor 3.

此处因为Xcode升级导致的插件失效,具体哪个暂时没有去关注,只找了修正的方法

:~ user$ find ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins/ -name Info.plist -maxdepth 3|xargs -I{} defaults write {} DVTPlugInCompatibilityUUIDs -array-add UUID

输入这条命令即可将uuid注入那个插件的info.plist,然后再按上面的流程查询就正常了

2. 下载 vapor

:~ user$ brew install vapor/tap/vapor

该命令可能会先 update brew,中间可能会有错误,具体情况具体分析

3. 上面完成了之后,切换到自己想要创建项目的文件夹后,敲入以下命令

:自己创建的文件夹 user$ vapor new HelloVapor --api --branch=beta

然后就会开始创建过程,需要一段时间,创建成功后会打印下面的图案

Cloning Template [Done]
Updating Package Name [Done]
Initializing git repository [Done]

                                       **
                                     **~~**
                                   **~~~~~~**
                                 **~~~~~~~~~~**
                               **~~~~~~~~~~~~~~**
                             **~~~~~~~~~~~~~~~~~~**
                           **~~~~~~~~~~~~~~~~~~~~~~**
                          **~~~~~~~~~~~~~~~~~~~~~~~~**
                         **~~~~~~~~~~~~~~~~~~~~~~~~~~**
                        **~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
                        **~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
                        **~~~~~~~~~~~~~~~~~~~~~++++~~~**
                         **~~~~~~~~~~~~~~~~~~~++++~~~**
                          ***~~~~~~~~~~~~~~~++++~~~***
                            ****~~~~~~~~~~++++~~****
                               *****~~~~~~~~~*****
                                  *************
                         
                         _       __    ___   ___   ___
                        \ \  /  / /\  | |_) / / \ | |_)
                         \_\/  /_/--\ |_|   \_\_/ |_| \
                           a web framework for Swift

                     Project "HelloVapor" has been created.
              Type `cd HelloVapor` to enter the project directory.
            Use `vapor cloud deploy` to host your project for free!
                                     Enjoy!

4. 接下来关联xcode

:HelloVapor user$ vapor xcode

打印如下信息

Generating Xcode Project [Done]
Select the `Run` scheme to run.
Open Xcode project?
y/n> y
Opening Xcode project...

上面手动选y,就会用xcode打开工程了,运行的时候只要当前主机的8080端口没有被占用,则可以正常运行啦

 

以上是关于在MacOS上创建一个 hello Vapor 后台项目的主要内容,如果未能解决你的问题,请参考以下文章

在 MacOS 上将 Vapor 编译为独立应用程序

使用Swift4+Vapor写后端-初体验

为啥在 URL 中处理 Vapor GET 请求

在 MacOS 上构建 SwiftUI “Hello World”

国内首个完整的 Swift 服务端开源项目及详解 - 基于 Vapor 3 框架

哪个框架/包可用于 Swift Linux,也可用于 Vapor [关闭]