【发布时间】:2019-07-10 16:07:32
【问题描述】:
第一次发帖!
我是一名学习 swift 的学生,我正在上一个相当大的速成课程。上次我的教授开始教我们如何进行简单的 get 和 post 请求,但我仍在追赶,显然还没有掌握一些基础知识。
这是我第一次使用 Kitura,也是第二次使用 Swift 编码。出于某种原因,当我使用swift run 时,我得到了我的打印结果并突然出现“程序以退出代码结束:0”,而不是在我的 8080 端口上运行本地主机来验证我在localhost:8080/ 上的响应。
有人可以帮我弄清楚我没有看到什么吗?还是不了解服务器端 swift 和命令行?
print("Hello, world from Swift Main!")
import Kitura
//constant router
let router = Router()
//When the router gets a request (contains everything needed to interpret the request), the server will respond with (Hello World or whatever data)
router.get("/") { request, response, next in
response.send("Hello world from router.get") //response
next() //either end the route or go on to the next one
}
//What port for the server to run on
Kitura.addHTTPServer(onPort: 8080, with: router)
//Need to add routes before run(), either in different file or on main
Kitura.run()
谢谢!
【问题讨论】:
标签: swift macos localhost kitura