我正在使用Ubuntu 16.04并且无法遵循Vapor Toolbox的安装指南.我使用了指南中描述的swiftenv,并安装了Swift的Ubuntu 15.10版本,但是尝试安装工具箱会导致以下结果:
$ curl -sL toolbox.vapor.sh | bash
? Compatible
Downloading...
Compiling...
<unknown>:0: error: build had 1 command failures
error: exit(1): /home/william/.swiftenv/versions/DEVELOPMENT-SNAPSHOT-2016-09-06-a/usr/bin/swift-build-tool -f /home/william/workspace/.vapor-toolbox-0.10.2/vapor-toolbox/.build/release.yaml
Installing...
bash: line 24: .build/release/Executable: No such file or directory
Use vapor --help and vapor <command> --help to learn more.
Run Code Online (Sandbox Code Playgroud)
尝试'蒸汽'会导致:
$ vapor
vapor: command not found
Run Code Online (Sandbox Code Playgroud) 我正在试图弄清楚如何在IBM Bluemix中部署使用Vapor框架的Cloudfoundry应用程序.
IBM正在为他的平台使用他的框架Kitura开发服务器端Swift应用程序提供设施和指导.我认为作为Cloudfoundry提供者,使用正确的Swift buildpack,我们必须能够部署通用服务器端Swift代码.
最后,在学习CF的部分时,我达到了使用CloudFoundry CLI的程度:
但是当我加载页面(https://sommobilitatcore.eu-gb.mybluemix.net/)时,我得到:
404 Not Found: Requested route ('sommobilitatcore.eu-gb.mybluemix.net') does not exist.
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我吗?谢谢!
一些背景:
manifest.yml:
applications:
- path: .
memory: 256M
instances: 1
name: SomMobilitatCore
disk_quota: 1024M
buildpack: https://github.com/IBM-Swift/swift-buildpack.git
Run Code Online (Sandbox Code Playgroud)
Procfile
web: App
Run Code Online (Sandbox Code Playgroud)
(main.swift在Source/App /中)
在Vapor Config文件中没有配置端口,然后Vapor正在尝试侦听端口80:
import Vapor
import HTTP
let drop = Droplet()
let _ = drop.config["app", "key"]?.string ?? ""
drop.get("/") { request in
return try drop.view.make("welcome.html")
}
(...)
let port = drop.config["app", "port"]?.int …Run Code Online (Sandbox Code Playgroud) 我正在尝试连接到我的 Heroku PostgreSQL 数据库,但出现以下错误:
cannotEstablishConnection("FATAL: no pg_hba.conf entry for host \"37.167.93.189\", user \"clpnkpyttmdtyq\", database \"d3h6147v73mgtu\", SSL off\n")
Run Code Online (Sandbox Code Playgroud)
我知道 Heroku postgres 数据库需要使用 SSL 连接,但我不知道如何在我的Droplet对象上配置连接。
这是我的postgresql.json配置文件:
{
"host": "ec2-54-163-224-108.compute-1.amazonaws.com",
"user": "clpnkpyttmdtyq",
"password": "99201aa07c48e18e7bdf210937857b85bee37cd8d8cb904381b1ddff934c7a4f",
"database": "d3h6147v73mgtu",
"port": 5432
}
Run Code Online (Sandbox Code Playgroud)
也许有ssl我不知道的参数?
我如何添加VaporPostgresSQLProvider:
let drop = Droplet()
// Tell the droplet to use our SQL provider service
try drop.addProvider(VaporPostgreSQL.Provider.self)
Run Code Online (Sandbox Code Playgroud)
有任何想法吗 ?
当我尝试使用本地 postgres 数据库时,它可以工作,因为它不需要 ssl 连接。
我可以使用计时器,例如NSTimer在Vapor(服务器端Swift)中吗?
我希望用Vapor编写的服务器可以偶尔主动执行一些任务.例如,每15分钟从网上轮询一些数据.
如何用Vapor实现这一目标?
我想用我的代码编译Vapor作为MacOS应用程序,所以我可以将它放在内部服务器上(拖动并单击以启动它).我宁愿不必在服务器上安装Xcode,swift和其他开发文件.我是蒸汽和快速的新手.当我从xCode构建它时,我运行的东西.其他人问他们是否可以将其嵌入应用程序,是的,没有回应.是的并没有就如何做到这一点提供任何指导.它可以编译成独立的OSX应用程序吗?我需要做些什么来实现它?如果你知道的话,请指教我.我编译了独立的应用程序.只是不知道怎么做Vapor.谢谢
给出以下示例模型(选择2个显示1-n关系的简单示例):
final class Company: MySQLModel {
var id: Int?
var name: String
}
final class Client: MySQLModel {
var id: Int?
var attr1: Int
var attr2: String
var companyId: Company.ID
static func prepare(on connection: MySQLDatabase.Connection) -> Future<Void> {
return Database.create(self, on: connection, closure: { builder in
try addProperties(to: builder)
builder.addReference(from: \.companyId, to: \Company.id, actions: .update)
})
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法获取和返回JOINED查询的结果(例如:公司 - 客户端//一对多)而无需原始查询?我尝试使用Query和Relationships但是没有办法一次性获取所有这些.
理想情况下,返回的数据将具有如下嵌套结构:
预期:
{
"name": "Alice",
"id": 0000000001,
"company": {
"id": 11111111,
"name": "Stack Overflow"
}
}
Run Code Online (Sandbox Code Playgroud)
如何在带有HTTPRequest结构的Vapor 3中发送API请求?
我尝试了以下代码的变体..
var headers: HTTPHeaders = .init()
let body = HTTPBody(string: a)
let httpReq = HTTPRequest(
method: .POST,
url: URL(string: "/post")!,
headers: headers,
body: body)
let httpRes: EventLoopFuture<HTTPResponse> = HTTPClient.connect(hostname: "httpbin.org", on: req).map(to: HTTPResponse.self) { client in
return client.send(httpReq)
}
Run Code Online (Sandbox Code Playgroud)
编译错误 Cannot convert value of type '(HTTPClient) -> EventLoopFuture<HTTPResponse>' to expected argument type '(HTTPClient) -> _'
我尝试了其他有效的代码变体。
let client = try req.make(Client.self)
let response: Future<Response> = client.get("http://example.vapor.codes/json")
Run Code Online (Sandbox Code Playgroud)
我阅读并重新阅读:
我已成功让 Vapor 应用程序从 Firestore 读取和写入集合和文档,但我现在有一个需要查询的用例。我已遵循 Firestore 查询的文档,并在我的 iOS 客户端中成功使用它们,该客户端使用 iOS Firestore 库而不是 REST API,但在服务器上我一直无法弄清楚如何执行相同的操作询问。Firestore 文档在这方面似乎不完整。
Google 的这个 API 端点工具确实允许我提交查询,但关于如何格式化 RunQuery 端点的请求正文中的字段的文档似乎很少。
有没有人有经验可以分享如何格式化请求正文以使用 REST API 创建格式良好的 Firestore 查询?
FWIW,这篇 Medium 文章对于 REST API 入门来说非常棒,但在更丰富的 Firestore 请求方面就停止了。 https://medium.com/rocket-fuel/getting-started-with-firebase-for-server-side-swift-93c11098702a
我在做教程时遇到了这个错误。我无法解决问题。因此,我删除了该项目并创建了一个新的简单项目来找出问题,但仍然存在相同的问题。我正在发布相关代码 -
package.swift 代码 -
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "dep",
products: [
.library(name: "dep", targets: ["App"]),
],
dependencies: [
// A server-side Swift web framework.
.package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"),
// Swift ORM (queries, models, relations, etc) built on SQLite 3.
.package(url: "https://github.com/vapor/fluent-sqlite.git", from: "3.0.0"),
.package(url: "https://github.com/vapor/leaf.git", from: "3.0.0"),
],
targets: [
.target(name: "App", dependencies: ["Leaf","FluentSQLite", "Vapor"]),
.target(name: "Run", dependencies: ["App"]),
.testTarget(name: "AppTests", dependencies: ["App"])
]
Run Code Online (Sandbox Code Playgroud)
)
当我在终端中执行“vapor build”并按回车键时,终端显示错误 - “”/Users/apple/dep: error: package at …
一般来说,我对 Vapor 和后端逻辑非常陌生。\n我正在使用 Leaf 构建一个简单的 Web 应用程序,我正在尝试从 psql 数据库读取数据并将其显示在 html/css (leaf) 中页。\n问题是,当我将参数传递到页面时,它不会加载 css 和图像。
\n\n这是我的控制器中的功能
\n\nmy project configuration:\n\nApp\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Package.swift\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Resources\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Views\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 index.leaf\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Public\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 images (images resources)\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 styles (css resources)\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 Sources\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 App\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Controllers\n \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 PoesiaController.swift\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Models\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 Poesia.swift\n\nfinal class PoesiaController {\n\nfunc createView(_ req: Request) throws -> Future<View> {\n let id: Int = try req.parameters.next(Int.self)\n return Poesia.find(id, on: req).unwrap(or: NSError(domain: "errore", code: 1, userInfo: nil)).flatMap(to: View.self) { p in\n return try …Run Code Online (Sandbox Code Playgroud)