Skip to content

Commit

Permalink
Swift v6
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewBarba committed Apr 5, 2024
1 parent 2a76401 commit 5f0a071
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 71 deletions.
7 changes: 7 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"indentation" : {
"spaces": 4
},
"tabWidth": 4,
"version": 1
}
97 changes: 53 additions & 44 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,107 +5,107 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/swift-server/async-http-client.git",
"state" : {
"revision" : "16f7e62c08c6969899ce6cc277041e868364e5cf",
"version" : "1.19.0"
"revision" : "291438696abdd48d2a83b52465c176efbd94512b",
"version" : "1.20.1"
}
},
{
"identity" : "async-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/async-kit.git",
"state" : {
"revision" : "eab9edff78e8ace20bd7cb6e792ab46d54f59ab9",
"version" : "1.18.0"
"revision" : "7ece208cd401687641c88367a00e3ea2b04311f1",
"version" : "1.19.0"
}
},
{
"identity" : "console-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/console-kit.git",
"state" : {
"revision" : "9a12000f4064a2bdc49068d7258292ec1bdc88fc",
"version" : "4.7.0"
"revision" : "a31f44ebfbd15a2cc0fda705279676773ac16355",
"version" : "4.14.1"
}
},
{
"identity" : "multipart-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/multipart-kit.git",
"state" : {
"revision" : "1adfd69df2da08f7931d4281b257475e32c96734",
"version" : "4.5.4"
"revision" : "12ee56f25bd3fc4c2d09c2aa16e69de61dc786e8",
"version" : "4.6.0"
}
},
{
"identity" : "routing-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/routing-kit.git",
"state" : {
"revision" : "e0539da5b60a60d7381f44cdcf04036f456cee2f",
"version" : "4.8.0"
"revision" : "2a92a7eac411a82fb3a03731be5e76773ebe1b3e",
"version" : "4.9.0"
}
},
{
"identity" : "swift-algorithms",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-algorithms.git",
"state" : {
"revision" : "b14b7f4c528c942f121c8b860b9410b2bf57825e",
"version" : "1.0.0"
"revision" : "f6919dfc309e7f1b56224378b11e28bab5bccc42",
"version" : "1.2.0"
}
},
{
"identity" : "swift-atomics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-atomics.git",
"state" : {
"revision" : "6c89474e62719ddcc1e9614989fff2f68208fe10",
"version" : "1.1.0"
"revision" : "cd142fd2f64be2100422d658e7411e39489da985",
"version" : "1.2.0"
}
},
{
"identity" : "swift-aws-lambda-runtime",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swift-server/swift-aws-lambda-runtime.git",
"state" : {
"revision" : "de730b240df25897c4b5b68889c178c994fd6817",
"version" : "1.0.0-alpha.1"
"revision" : "8d9f44b7838750b103ad2ad49055e8333d719e8a",
"version" : "1.0.0-alpha.2"
}
},
{
"identity" : "swift-backtrace",
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swift-server/swift-backtrace.git",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "f25620d5d05e2f1ba27154b40cafea2b67566956",
"version" : "1.3.3"
"revision" : "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb",
"version" : "1.1.0"
}
},
{
"identity" : "swift-collections",
"identity" : "swift-crypto",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"location" : "https://github.com/apple/swift-crypto",
"state" : {
"revision" : "937e904258d22af6e447a0b72c0bc67583ef64a2",
"version" : "1.0.4"
"revision" : "f0525da24dc3c6cbb2b6b338b65042bc91cbc4bb",
"version" : "3.3.0"
}
},
{
"identity" : "swift-crypto",
"identity" : "swift-http-types",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-crypto",
"location" : "https://github.com/apple/swift-http-types",
"state" : {
"revision" : "60f13f60c4d093691934dc6cfdf5f508ada1f894",
"version" : "2.6.0"
"revision" : "12358d55a3824bd5fed310b999ea8cf83a9a1a65",
"version" : "1.0.3"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"state" : {
"revision" : "532d8b529501fb73a2455b179e0bbb6d49b652ed",
"version" : "1.5.3"
"revision" : "e97a6fcb1ab07462881ac165fdbb37f067e205d5",
"version" : "1.5.4"
}
},
{
Expand All @@ -122,44 +122,44 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "cf281631ff10ec6111f2761052aa81896a83a007",
"version" : "2.58.0"
"revision" : "fc63f0cf4e55a4597407a9fc95b16a2bc44b4982",
"version" : "2.64.0"
}
},
{
"identity" : "swift-nio-extras",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-extras.git",
"state" : {
"revision" : "0e0d0aab665ff1a0659ce75ac003081f2b1c8997",
"version" : "1.19.0"
"revision" : "a3b640d7dc567225db7c94386a6e71aded1bfa63",
"version" : "1.22.0"
}
},
{
"identity" : "swift-nio-http2",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-http2.git",
"state" : {
"revision" : "a8ccf13fa62775277a5d56844878c828bbb3be1a",
"version" : "1.27.0"
"revision" : "0904bf0feb5122b7e5c3f15db7df0eabe623dd87",
"version" : "1.30.0"
}
},
{
"identity" : "swift-nio-ssl",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-ssl.git",
"state" : {
"revision" : "320bd978cceb8e88c125dcbb774943a92f6286e9",
"version" : "2.25.0"
"revision" : "7c381eb6083542b124a6c18fae742f55001dc2b5",
"version" : "2.26.0"
}
},
{
"identity" : "swift-nio-transport-services",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-transport-services.git",
"state" : {
"revision" : "e7403c35ca6bb539a7ca353b91cc2d8ec0362d58",
"version" : "1.19.0"
"revision" : "6cbe0ed2b394f21ab0d46b9f0c50c6be964968ce",
"version" : "1.20.1"
}
},
{
Expand All @@ -171,22 +171,31 @@
"version" : "1.0.2"
}
},
{
"identity" : "swift-system",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-system.git",
"state" : {
"revision" : "025bcb1165deab2e20d4eaba79967ce73013f496",
"version" : "1.2.1"
}
},
{
"identity" : "vapor",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/vapor",
"state" : {
"revision" : "1bb4a2ed94bec7a92f92e82896408c785d068f5c",
"version" : "4.79.0"
"revision" : "11cdb29614a5c7f8c5289f3c97b3398c3d89b395",
"version" : "4.92.5"
}
},
{
"identity" : "websocket-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/websocket-kit.git",
"state" : {
"revision" : "53fe0639a98903858d0196b699720decb42aee7b",
"version" : "2.14.0"
"revision" : "4232d34efa49f633ba61afde365d3896fc7f8740",
"version" : "2.15.0"
}
}
],
Expand Down
59 changes: 37 additions & 22 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,43 +1,58 @@
// swift-tools-version: 5.6
// swift-tools-version: 5.9

import PackageDescription

let package = Package(
name: "Vercel",
platforms: [
.macOS(.v12),
.iOS(.v15),
.tvOS(.v15),
.watchOS(.v8)
.macOS(.v12)
],
products: [
.library(name: "Vercel", targets: ["Vercel"]),
.library(name: "VercelVapor", targets: ["VercelVapor"]),
.plugin(name: "VercelPackager", targets: ["VercelPackager"])
.plugin(name: "VercelPackager", targets: ["VercelPackager"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-crypto", "1.0.0" ..< "3.0.0"),
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime", from: "1.0.0-alpha.1"),
.package(url: "https://github.com/vapor/vapor", from: "4.0.0")
.package(url: "https://github.com/apple/swift-crypto", from: "3.0.0"),
.package(
url: "https://github.com/swift-server/swift-aws-lambda-runtime", from: "1.0.0-alpha.2"),
.package(url: "https://github.com/vapor/vapor", from: "4.0.0"),
],
targets: [
.target(name: "Vercel", dependencies: [
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
.product(name: "Crypto", package: "swift-crypto")
]),
.target(name: "VercelVapor", dependencies: [
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
.product(name: "Vapor", package: "vapor"),
.byName(name: "Vercel")
]),
.target(
name: "Vercel",
dependencies: [
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
.product(name: "Crypto", package: "swift-crypto"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.target(
name: "VercelVapor",
dependencies: [
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
.product(name: "Vapor", package: "vapor"),
.byName(name: "Vercel"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.plugin(
name: "VercelPackager",
capability: .command(
intent: .custom(verb: "vercel", description: "Build and deploy your Swift application to Vercel")
intent: .custom(
verb: "vercel", description: "Build and deploy your Swift application to Vercel"
)
)
),
.testTarget(name: "VercelTests", dependencies: [
.byName(name: "Vercel")
])
.testTarget(
name: "VercelTests",
dependencies: [
.byName(name: "Vercel")
]
),
]
)
13 changes: 8 additions & 5 deletions Sources/VercelVapor/VaporHandler.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// VaporHandler.swift
//
//
//
// Created by Andrew Barba on 8/25/23.
//
Expand Down Expand Up @@ -29,13 +29,15 @@ extension VaporHandler {
// Configure vercel server
app.servers.use(.vercel)
// Start the application
try app.start()
try await app.startup()
// Cache the app instance
Shared.app = app
await MainActor.run {
Shared.app = app
}
}

public func onRequest(_ req: Vercel.Request) async throws -> Vercel.Response {
guard let app = Shared.app else {
guard let app = await Shared.app else {
return .status(.serviceUnavailable).send("Vapor application not configured")
}
let vaporRequest = try Vapor.Request.from(request: req, for: app)
Expand All @@ -44,8 +46,9 @@ extension VaporHandler {
}
}

fileprivate struct Shared {
private struct Shared {

@MainActor
static var app: Application?
}

Expand Down

0 comments on commit 5f0a071

Please sign in to comment.