Initial Commit
It should work for everyone
This commit is contained in:
parent
9772717a20
commit
c2539d2250
@ -20,7 +20,13 @@
|
||||
],
|
||||
|
||||
// The WorkspaceFolder inside container
|
||||
"workspaceFolder": "/workspace"
|
||||
"workspaceFolder": "/workspace",
|
||||
|
||||
// RunArgs
|
||||
"runArgs": [
|
||||
"--name",
|
||||
"IoT-Simulator-Vapor"
|
||||
]
|
||||
|
||||
|
||||
}
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@ -108,11 +108,9 @@ DerivedData/
|
||||
Package.resolved
|
||||
.swiftpm
|
||||
Tests/LinuxMain.swift
|
||||
.vscode
|
||||
.bash_history
|
||||
.cache/
|
||||
|
||||
# API Docs Generation
|
||||
generate-package-api-docs.swift
|
||||
public/
|
||||
theme-settings.json
|
||||
22
.vscode/launch.json
vendored
Normal file
22
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder:workspace}",
|
||||
"name": "Debug IoT-Simulator",
|
||||
"program": "${workspaceFolder:workspace}/.build/debug/IoT-Simulator",
|
||||
"preLaunchTask": "swift: Build Debug IoT-Simulator"
|
||||
},
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder:workspace}",
|
||||
"name": "Release IoT-Simulator",
|
||||
"program": "${workspaceFolder:workspace}/.build/release/IoT-Simulator",
|
||||
"preLaunchTask": "swift: Build Release IoT-Simulator"
|
||||
}
|
||||
]
|
||||
}
|
||||
1
.vscode/settings.json
vendored
Normal file
1
.vscode/settings.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{}
|
||||
40
Package.swift
Normal file
40
Package.swift
Normal file
@ -0,0 +1,40 @@
|
||||
// swift-tools-version:6.0
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "template-bare",
|
||||
platforms: [
|
||||
.macOS(.v13)
|
||||
],
|
||||
dependencies: [
|
||||
// 💧 A server-side Swift web framework.
|
||||
.package(url: "https://github.com/vapor/vapor.git", from: "4.99.3"),
|
||||
// 🔵 Non-blocking, event-driven networking for Swift. Used for custom executors
|
||||
.package(url: "https://github.com/apple/swift-nio.git", from: "2.65.0"),
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
name: "App",
|
||||
dependencies: [
|
||||
.product(name: "Vapor", package: "vapor"),
|
||||
.product(name: "NIOCore", package: "swift-nio"),
|
||||
.product(name: "NIOPosix", package: "swift-nio"),
|
||||
],
|
||||
swiftSettings: swiftSettings
|
||||
),
|
||||
.testTarget(
|
||||
name: "AppTests",
|
||||
dependencies: [
|
||||
.target(name: "App"),
|
||||
.product(name: "XCTVapor", package: "vapor"),
|
||||
],
|
||||
swiftSettings: swiftSettings
|
||||
)
|
||||
],
|
||||
swiftLanguageModes: [.v5]
|
||||
)
|
||||
|
||||
var swiftSettings: [SwiftSetting] { [
|
||||
.enableUpcomingFeature("DisableOutwardActorInference"),
|
||||
.enableExperimentalFeature("StrictConcurrency"),
|
||||
] }
|
||||
0
Public/.gitkeep
Normal file
0
Public/.gitkeep
Normal file
0
Sources/App/Controllers/.gitkeep
Normal file
0
Sources/App/Controllers/.gitkeep
Normal file
9
Sources/App/configure.swift
Normal file
9
Sources/App/configure.swift
Normal file
@ -0,0 +1,9 @@
|
||||
import Vapor
|
||||
|
||||
// configures your application
|
||||
public func configure(_ app: Application) async throws {
|
||||
// uncomment to serve files from /Public folder
|
||||
// app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
|
||||
// register routes
|
||||
try routes(app)
|
||||
}
|
||||
31
Sources/App/entrypoint.swift
Normal file
31
Sources/App/entrypoint.swift
Normal file
@ -0,0 +1,31 @@
|
||||
import Vapor
|
||||
import Logging
|
||||
import NIOCore
|
||||
import NIOPosix
|
||||
|
||||
@main
|
||||
enum Entrypoint {
|
||||
static func main() async throws {
|
||||
var env = try Environment.detect()
|
||||
try LoggingSystem.bootstrap(from: &env)
|
||||
|
||||
let app = try await Application.make(env)
|
||||
|
||||
// This attempts to install NIO as the Swift Concurrency global executor.
|
||||
// You can enable it if you'd like to reduce the amount of context switching between NIO and Swift Concurrency.
|
||||
// Note: this has caused issues with some libraries that use `.wait()` and cleanly shutting down.
|
||||
// If enabled, you should be careful about calling async functions before this point as it can cause assertion failures.
|
||||
// let executorTakeoverSuccess = NIOSingletons.unsafeTryInstallSingletonPosixEventLoopGroupAsConcurrencyGlobalExecutor()
|
||||
// app.logger.debug("Tried to install SwiftNIO's EventLoopGroup as Swift's global concurrency executor", metadata: ["success": .stringConvertible(executorTakeoverSuccess)])
|
||||
|
||||
do {
|
||||
try await configure(app)
|
||||
} catch {
|
||||
app.logger.report(error: error)
|
||||
try? await app.asyncShutdown()
|
||||
throw error
|
||||
}
|
||||
try await app.execute()
|
||||
try await app.asyncShutdown()
|
||||
}
|
||||
}
|
||||
11
Sources/App/routes.swift
Normal file
11
Sources/App/routes.swift
Normal file
@ -0,0 +1,11 @@
|
||||
import Vapor
|
||||
|
||||
func routes(_ app: Application) throws {
|
||||
app.get { req async in
|
||||
"It works!"
|
||||
}
|
||||
|
||||
app.get("hello") { req async -> String in
|
||||
"Hello, world!"
|
||||
}
|
||||
}
|
||||
29
Tests/AppTests/AppTests.swift
Normal file
29
Tests/AppTests/AppTests.swift
Normal file
@ -0,0 +1,29 @@
|
||||
@testable import App
|
||||
import XCTVapor
|
||||
import Testing
|
||||
|
||||
@Suite("App Tests")
|
||||
struct AppTests {
|
||||
private func withApp(_ test: (Application) async throws -> ()) async throws {
|
||||
let app = try await Application.make(.testing)
|
||||
do {
|
||||
try await configure(app)
|
||||
try await test(app)
|
||||
}
|
||||
catch {
|
||||
try await app.asyncShutdown()
|
||||
throw error
|
||||
}
|
||||
try await app.asyncShutdown()
|
||||
}
|
||||
|
||||
@Test("Test Hello World Route")
|
||||
func helloWorld() async throws {
|
||||
try await withApp { app in
|
||||
try await app.test(.GET, "hello", afterResponse: { res async in
|
||||
#expect(res.status == .ok)
|
||||
#expect(res.body.string == "Hello, world!")
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user