Skip to content

Commit 2e1ab06

Browse files
committed
Examples: Adopt structure used in Vapor template
1 parent 3fa1d83 commit 2e1ab06

File tree

3 files changed

+58
-7
lines changed

3 files changed

+58
-7
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the SwiftContainerPlugin open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the SwiftContainerPlugin project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of SwiftContainerPlugin project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import Vapor
16+
17+
public func configure(_ app: Application) async throws {
18+
try routes(app)
19+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the SwiftContainerPlugin open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the SwiftContainerPlugin project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of SwiftContainerPlugin project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import Vapor
16+
17+
@main
18+
enum Entrypoint {
19+
static func main() async throws {
20+
let env = try Environment.detect()
21+
let app = try await Application.make(env)
22+
23+
do {
24+
try await configure(app)
25+
try await app.execute()
26+
} catch {
27+
app.logger.report(error: error)
28+
try? await app.asyncShutdown()
29+
throw error
30+
}
31+
try await app.asyncShutdown()
32+
}
33+
}

Examples/HelloWorldVapor/Sources/main.swift renamed to Examples/HelloWorldVapor/Sources/routes.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the SwiftContainerPlugin open source project
44
//
5-
// Copyright (c) 2024 Apple Inc. and the SwiftContainerPlugin project authors
5+
// Copyright (c) 2025 Apple Inc. and the SwiftContainerPlugin project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -17,10 +17,9 @@ import Vapor
1717

1818
let myos = ProcessInfo.processInfo.operatingSystemVersionString
1919

20-
let app = try Application(.detect())
21-
app.http.server.configuration.hostname = "0.0.0.0"
22-
defer { app.shutdown() }
20+
func routes(_ app: Application) throws {
2321

24-
app.get { _ in "Hello World, from Vapor on \(myos)\n" }
25-
26-
try app.run()
22+
app.get { req async in
23+
"Hello World, from Vapor on \(myos)\n"
24+
}
25+
}

0 commit comments

Comments
 (0)