Created
August 18, 2019 18:48
-
-
Save araeuchle/6b1d389fd20eca9c4567dd9c8be1a9da to your computer and use it in GitHub Desktop.
This file contains hidden or 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 FluentMySQL | |
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(FluentMySQLProvider()) | |
// 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) | |
var databases = DatabasesConfig() | |
// Configure MySQL Database | |
let databaseConfig = MySQLDatabaseConfig( | |
hostname: Environment.get("DB_HOSTNAME")!, | |
username: Environment.get("DB_USER")!, | |
password: Environment.get("DB_PASSWORD")!, | |
database: Environment.get("DB_NAME")! | |
) | |
let database = MySQLDatabase(config: databaseConfig) | |
databases.add(database: database, as: .mysql) | |
services.register(database) | |
// Configure migrations | |
var migrations = MigrationConfig() | |
migrations.add(model: Dish.self, database: .mysql) | |
services.register(migrations) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment