Last active
December 21, 2019 12:38
-
-
Save hsharghi/b08598e88a8f71d1c6608afeee85e468 to your computer and use it in GitHub Desktop.
virgool-blog-0020
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import FluentSQLite | |
import Vapor | |
/// Called before your application initializes. | |
public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws { | |
// Register providers first | |
try services.register(FluentSQLiteProvider()) | |
// Register routes to the router | |
let router = EngineRouter.default() | |
try routes(router) | |
services.register(router, as: Router.self) | |
// Register middleware | |
var middlewares = MiddlewareConfig() // Create _empty_ middleware config | |
// middlewares.use(FileMiddleware.self) // Serves files from `Public/` directory | |
middlewares.use(ErrorMiddleware.self) // Catches errors and converts to HTTP response | |
services.register(middlewares) | |
//1 | |
// Configure a SQLite database | |
let sqlite = try SQLiteDatabase(storage: .file(path: "blog.sqlite")) | |
// Register the configured SQLite database to the database config. | |
var databases = DatabasesConfig() | |
databases.add(database: sqlite, as: .sqlite) | |
services.register(databases) | |
//2 | |
// Configure migrations | |
var migrations = MigrationConfig() | |
migrations.add(model: Post.self, database: .sqlite) | |
services.register(migrations) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment