Vapor - Hello World!

上一节我们已经把 Vapor 环境搭建完毕

拉取Vapor 项目代码

vapor new hello -n
  • 执行该指令可能会遇到找不到分支的问题,原因是因为github所谓的政治正确把master分支改为了main,所以提示找不到master,参考https://github.com/vapor/vapor/issues/2581
vapor new hello -n
Cloning template...
Error: Cloning into '/Users/Desktop/vapor/.vapor-template'...
fatal: Remote branch master not found in upstream origin
  • 如果遇到这种情况我建议直接clone template分支的代码吧 git clone https://github.com/vapor/template.git,可以理解为
vapor new hello -n 等同于 vapor new hello -n

编译和运行

等待 Swift Package Manager 的依赖项下载完成后,请点击 Run 以构建并运行你的项目。

此时,你应该可以在 Xcode 窗口的底部看到控制台弹出窗口输出的启动信息。

[ INFO ] Server starting on http://127.0.0.1:8080

本地访问

打开你的 Web 浏览器,然后访问 localhost:8080/hello

你应该能够看到以下页面内容:

Hello, world!

恭喜!成功地创建和运行了你的第一个 Vapor 应用程序! 🎉 🎉 🎉

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容