-
Notifications
You must be signed in to change notification settings - Fork 667
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dddf980
commit 0c1022b
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
]), | ||
|
||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |