Skip to content

Examples: Adopt structure used in the Vapor template repository #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/endtoend_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
cat ${{ matrix.example }}/Package.swift
swift package \
--package-path ${{ matrix.example }} \
-Xswiftc -warnings-as-errors \
--swift-sdk x86_64-swift-linux-musl \
--allow-network-connections all \
build-container-image \
Expand Down
4 changes: 2 additions & 2 deletions Examples/HelloWorldVapor/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ let package = Package(
name: "hello-world",
platforms: [.macOS(.v13)],
dependencies: [
.package(url: "https://github.com/vapor/vapor", .upToNextMajor(from: "4.102.0")),
.package(url: "https://github.com/apple/swift-container-plugin", from: "0.4.0"),
.package(url: "https://github.com/vapor/vapor", from: "4.102.0"),
.package(url: "https://github.com/apple/swift-container-plugin", from: "0.5.0"),
],
targets: [.executableTarget(name: "hello-world", dependencies: [.product(name: "Vapor", package: "vapor")])]
)
19 changes: 19 additions & 0 deletions Examples/HelloWorldVapor/Sources/configure.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftContainerPlugin open source project
//
// Copyright (c) 2025 Apple Inc. and the SwiftContainerPlugin project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftContainerPlugin project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import Vapor

func configure(_ app: Application) async throws {
try routes(app)
}
34 changes: 34 additions & 0 deletions Examples/HelloWorldVapor/Sources/entrypoint.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftContainerPlugin open source project
//
// Copyright (c) 2025 Apple Inc. and the SwiftContainerPlugin project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftContainerPlugin project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import Vapor

@main
enum Entrypoint {
static func main() async throws {
let env = try Environment.detect()
let app = try await Application.make(env)
app.http.server.configuration.hostname = "0.0.0.0"

do {
try await configure(app)
try await app.execute()
} catch {
app.logger.report(error: error)
try? await app.asyncShutdown()
throw error
}
try await app.asyncShutdown()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the SwiftContainerPlugin open source project
//
// Copyright (c) 2024 Apple Inc. and the SwiftContainerPlugin project authors
// Copyright (c) 2025 Apple Inc. and the SwiftContainerPlugin project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
Expand All @@ -17,10 +17,8 @@ import Vapor

let myos = ProcessInfo.processInfo.operatingSystemVersionString

let app = try Application(.detect())
app.http.server.configuration.hostname = "0.0.0.0"
defer { app.shutdown() }

app.get { _ in "Hello World, from Vapor on \(myos)\n" }

try app.run()
func routes(_ app: Application) throws {
app.get { req async in
"Hello World, from Vapor on \(myos)\n"
}
}