Skip to content

Commit 2f655ca

Browse files
committed
Fix Vapor handler
1 parent 081a50f commit 2f655ca

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Sources/VercelVapor/VaporHandler.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,12 @@ extension VaporHandler {
2828
try await configure(app: app)
2929
// Configure vercel server
3030
app.servers.use(.vercel)
31-
// Start the application
32-
try await app.startup()
3331
// Cache the app instance
34-
await MainActor.run {
35-
Shared.app = app
36-
}
32+
await Shared.default.setApp(app)
3733
}
3834

3935
public func onRequest(_ req: Vercel.Request) async throws -> Vercel.Response {
40-
guard let app = await Shared.app else {
36+
guard let app = await Shared.default.app else {
4137
return .status(.serviceUnavailable).send("Vapor application not configured")
4238
}
4339
let vaporRequest = try Vapor.Request.from(request: req, for: app)
@@ -46,10 +42,15 @@ extension VaporHandler {
4642
}
4743
}
4844

49-
private struct Shared {
45+
private actor Shared {
46+
47+
static let `default` = Shared()
5048

51-
@MainActor
52-
static var app: Application?
49+
private(set) var app: Application?
50+
51+
func setApp(_ app: Application) {
52+
self.app = app
53+
}
5354
}
5455

5556
extension Vapor.Request {

0 commit comments

Comments
 (0)