Skip to content

Commit

Permalink
swift flying fox added
Browse files Browse the repository at this point in the history
  • Loading branch information
ceopaludetto committed Oct 15, 2024
1 parent dddf980 commit 0c1022b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
31 changes: 31 additions & 0 deletions swift/flying-fox/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// swift-tools-version:5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "server",
platforms: [
.macOS("10.15")
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/swhitty/FlyingFox.git", .upToNextMajor(from: "0.18.0"))
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "server",
dependencies: [
.product(name: "FlyingFox", package: "FlyingFox")
],
swiftSettings: [
// Enable better optimizations when building in Release configuration. Despite the use of
// the `.unsafeFlags` construct required by SwiftPM, this flag is recommended for Release
// builds. See <https://github.com/swift-server/guides#building-for-production> for details.
.unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))
]),

]
)
23 changes: 23 additions & 0 deletions swift/flying-fox/Sources/server/Server.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import FlyingFox

@main
struct Server {
static func main() async throws {
let server = HTTPServer(port: 3000)

await server.appendRoute("GET /") { _ in
return HTTPResponse(statusCode: .ok)
}

await server.appendRoute("GET /user/:id") { request in
let user = request.routeParameters["id"] ?? ""
return HTTPResponse(statusCode: .ok, body: user.data(using: .utf8)!)
}

await server.appendRoute("GET /user") { request in
return HTTPResponse(statusCode: .ok)
}

try await server.start()
}
}
4 changes: 4 additions & 0 deletions swift/flying-fox/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
framework:
github: swhitty/FlyingFox
version: 0.18.0
name: flying-fox

0 comments on commit 0c1022b

Please sign in to comment.