feat: Begins snapshot testing for html
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import Dependencies
|
||||
import Elementary
|
||||
import Vapor
|
||||
import VaporElementary
|
||||
|
||||
@@ -8,15 +8,19 @@ import Vapor
|
||||
struct DependenciesMiddleware: AsyncMiddleware {
|
||||
|
||||
private let values: DependencyValues.Continuation
|
||||
private let database: DatabaseClient
|
||||
|
||||
init() {
|
||||
init(
|
||||
database: DatabaseClient
|
||||
) {
|
||||
self.values = withEscapedDependencies { $0 }
|
||||
self.database = database
|
||||
}
|
||||
|
||||
func respond(to request: Request, chainingTo next: any AsyncResponder) async throws -> Response {
|
||||
try await values.yield {
|
||||
try await withDependencies {
|
||||
$0.database = .live(database: request.db)
|
||||
$0.database = database
|
||||
$0.dateFormatter = .liveValue
|
||||
} operation: {
|
||||
try await next.respond(to: request)
|
||||
|
||||
@@ -8,7 +8,10 @@ import Vapor
|
||||
@preconcurrency import VaporRouting
|
||||
|
||||
// configures your application
|
||||
public func configure(_ app: Application) async throws {
|
||||
public func configure(
|
||||
_ app: Application,
|
||||
makeDatabaseClient: @escaping (any Database) -> DatabaseClient = { .live(database: $0) }
|
||||
) async throws {
|
||||
// cors middleware should come before default error middleware using `at: .beginning`
|
||||
let corsConfiguration = CORSMiddleware.Configuration(
|
||||
allowedOrigin: .all,
|
||||
@@ -21,7 +24,6 @@ public func configure(_ app: Application) async throws {
|
||||
|
||||
app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
|
||||
app.middleware.use(app.sessions.middleware)
|
||||
app.middleware.use(DependenciesMiddleware())
|
||||
|
||||
#if DEBUG
|
||||
app.lifecycle.use(BrowserSyncHandler())
|
||||
@@ -35,8 +37,13 @@ public func configure(_ app: Application) async throws {
|
||||
app.databases.use(DatabaseConfigurationFactory.sqlite(.memory), as: .sqlite)
|
||||
}
|
||||
|
||||
let databaseClient = DatabaseClient.live(database: app.db)
|
||||
try await app.migrations.add(databaseClient.migrations())
|
||||
let databaseClient = makeDatabaseClient(app.db)
|
||||
|
||||
if app.environment != .testing {
|
||||
try await app.migrations.add(databaseClient.migrations())
|
||||
}
|
||||
|
||||
app.middleware.use(DependenciesMiddleware(database: databaseClient))
|
||||
|
||||
app.mount(
|
||||
SiteRoute.router,
|
||||
@@ -50,7 +57,9 @@ public func configure(_ app: Application) async throws {
|
||||
use: siteHandler
|
||||
)
|
||||
|
||||
try await app.autoMigrate()
|
||||
if app.environment != .testing {
|
||||
try await app.autoMigrate()
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
app.asyncCommands.use(SeedCommand(), as: "seed")
|
||||
|
||||
Reference in New Issue
Block a user