🙋 嗨,你好!
请注意:本项目仍处于 Alpha 版本,我们正在积极地从 SwiftEngine 中移植许多优秀的功能,使其与 SwiftNIO 兼容。我们欢迎任何贡献者或测试人员加入我们的项目!
以下说明将引导您在本地机器上启动并运行项目副本,以用于开发和测试目的。有关如何在生产系统上部署项目的说明,请参阅部署部分。
我们需要哪些依赖项才能使其工作?
操作系统 | 版本 |
---|---|
macOS | 10.13+ |
Ubuntu | 14.04, 16.04, 16.10 |
git clone https://github.com/swiftengine/SwiftEngine.git
cd
到 SwiftEngine
目录并运行 sudo ./install.sh
./run.sh
这应该启动服务器并监听端口 8887
编写您的站点
/var/swiftengine/www/
目录中创建一个新的 mypage.swift
文件(见下面的例子)http://<machine_ip>:8887/mypage
(默认情况下是 localhost:8887
)就是这样!无需编译或处理 shell 转储!您请求的端点将在首次请求期间自动编译,并显示结果。
您放置在 /var/swiftengine/www
中的任何 swift 文件都可以通过浏览器访问,无需 .swift
扩展名。阅读更多关于 SwiftEngine 的自主系统和路由逻辑的信息(这里)
// Import SwiftEngine essentials
import SwiftEngine
// specify other required files for this file
//se: require /common.swift
// Entry Point function; where all code begins
func entryPoint(ctx: RequestContext) {
// add GET handlers to the request context
ctx.addHandler(forMethod:"GET", withRoute:"*"){
req, res in
res.write("Hello from SwiftEngine!")
}
// add POST handlers to the request context
ctx.addHandler(forMethod:"POST", withRoute:"*"){
req, res in
res.write("Handle for POST request method")
}
// add catch-all handlers to the request context
ctx.addHandler(forMethod:"*", withRoute:"*"){
req, res in
res.write("Handle for catch-all")
}
}
我们很乐意听取您关于 SwiftEngine 的想法和反馈。如果您想为我们的项目做出贡献或有想要提出的问题,请访问我们的 CONTRIBUTING 文档以了解更多详情。
本项目根据 Mozilla Public License Version 2.0 许可证获得许可 - 有关详细信息,请参阅 LICENSE 文件