mirror of
https://github.com/vapor/template.git
synced 2025-05-15 18:23:20 +08:00
Compare commits
2 Commits
9a04f7480a
...
3bf55dbe84
Author | SHA1 | Date | |
---|---|---|---|
|
3bf55dbe84 | ||
|
7605eb3491 |
@ -16,19 +16,17 @@ public func configure(_ app: Application) async throws {
|
||||
password: Environment.get("DATABASE_PASSWORD") ?? "vapor_password",
|
||||
database: Environment.get("DATABASE_NAME") ?? "vapor_database",
|
||||
tls: .prefer(try .init(configuration: .clientDefault)))
|
||||
), as: .psql){{/fluent.db.is_postgres}}{{#fluent.db.is_mysql}} app.databases.use(DatabaseConfigurationFactory.mysql(
|
||||
), as: .psql){{/fluent.db.is_postgres}}{{#fluent.db.is_mysql}}app.databases.use(DatabaseConfigurationFactory.mysql(
|
||||
hostname: Environment.get("DATABASE_HOST") ?? "localhost",
|
||||
port: Environment.get("DATABASE_PORT").flatMap(Int.init(_:)) ?? MySQLConfiguration.ianaPortNumber,
|
||||
username: Environment.get("DATABASE_USERNAME") ?? "vapor_username",
|
||||
password: Environment.get("DATABASE_PASSWORD") ?? "vapor_password",
|
||||
database: Environment.get("DATABASE_NAME") ?? "vapor_database"
|
||||
), as: .mysql){{/fluent.db.is_mysql}}{{#fluent.db.is_sqlite}} app.databases.use(DatabaseConfigurationFactory.sqlite(.file("db.sqlite")), as: .sqlite){{/fluent.db.is_sqlite}}
|
||||
), as: .mysql){{/fluent.db.is_mysql}}{{#fluent.db.is_sqlite}}app.databases.use(DatabaseConfigurationFactory.sqlite(.file("db.sqlite")), as: .sqlite){{/fluent.db.is_sqlite}}
|
||||
|
||||
app.migrations.add(CreateTodo()){{/fluent}}{{#leaf}}
|
||||
|
||||
app.views.use(.leaf)
|
||||
|
||||
{{/leaf}}
|
||||
app.views.use(.leaf){{/leaf}}
|
||||
|
||||
// register routes
|
||||
try routes(app)
|
||||
|
@ -4,7 +4,7 @@
|
||||
func routes(_ app: Application) throws {
|
||||
{{#leaf}}app.get { req async throws in
|
||||
try await req.view.render("index", ["title": "Hello Vapor!"])
|
||||
}{{/leaf}}{{^leaf}} app.get { req async in
|
||||
}{{/leaf}}{{^leaf}}app.get { req async in
|
||||
"It works!"
|
||||
}{{/leaf}}
|
||||
|
||||
|
@ -11,14 +11,13 @@ struct AppTests {
|
||||
private func withApp(_ test: (Application) async throws -> ()) async throws {
|
||||
let app = try await Application.make(.testing)
|
||||
do {
|
||||
try await configure(app)
|
||||
{{#fluent}}try await app.autoMigrate()
|
||||
{{/fluent}} try await test(app)
|
||||
{{#fluent}}try await app.autoRevert()
|
||||
{{/fluent}} }
|
||||
catch {
|
||||
try await configure(app){{#fluent}}
|
||||
try await app.autoMigrate(){{/fluent}}
|
||||
try await test(app){{#fluent}}
|
||||
try await app.autoRevert(){{/fluent}}
|
||||
} catch {
|
||||
{{#fluent}}try? await app.autoRevert()
|
||||
{{/fluent}} try await app.asyncShutdown()
|
||||
{{/fluent}}try await app.asyncShutdown()
|
||||
throw error
|
||||
}
|
||||
try await app.asyncShutdown()
|
||||
|
Loading…
x
Reference in New Issue
Block a user