Refactor for flask

This commit is contained in:
Stephen
2020-06-01 14:31:12 -07:00
parent ef0961402d
commit 182926af1b
252 changed files with 25897 additions and 15 deletions

View File

@@ -1,12 +0,0 @@
import Vapor
// Creates an instance of `Application`. This is called from `main.swift` in the run target.
public func app(_ env: Environment) throws -> Application {
var config = Config.default()
var env = env
var services = Services.default()
try configure(&config, &env, &services)
let app = try Application(config: config, environment: env, services: services)
try boot(app)
return app
}

View File

@@ -1,6 +0,0 @@
import Vapor
// Called after your application has initialized.
public func boot(_ app: Application) throws {
// Your code here
}

View File

@@ -1,21 +0,0 @@
import Leaf
import Vapor
// Called before your application initializes.
public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {
// Register routes to the router
let router = EngineRouter.default()
try routes(router)
services.register(router, as: Router.self)
//leaf
try services.register(LeafProvider())
config.prefer(LeafRenderer.self, for: ViewRenderer.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)
}

View File

@@ -1,20 +0,0 @@
import Vapor
// Register your application's routes here.
public func routes(_ router: Router) throws {
router.get("") { request in
return try request.view().render("home")
}
router.get("index.html") { request in
return try request.view().render("home")
}
router.get("privacy") { request in
return try request.view().render("privacy")
}
router.get("404") { request in
return try request.view().render("404")
}
router.get("welcome") { request in
return try request.view().render("welcome")
}
}

View File

@@ -1,3 +0,0 @@
import App
try app(.detect()).run()