vapor 4
This commit is contained in:
18
Sources/App/configure.swift
Normal file
18
Sources/App/configure.swift
Normal file
@@ -0,0 +1,18 @@
|
||||
import Leaf
|
||||
import Vapor
|
||||
|
||||
// Called before your application initializes.
|
||||
public func configure(_ app: Application) throws {
|
||||
//leaf
|
||||
app.views.use(.leaf)
|
||||
|
||||
//Register middleware
|
||||
app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
|
||||
app.middleware.use(ErrorMiddleware.default(environment: app.environment))
|
||||
|
||||
//port
|
||||
app.http.server.configuration.port = 8080
|
||||
|
||||
//routes
|
||||
try routes(app)
|
||||
}
|
||||
20
Sources/App/routes.swift
Normal file
20
Sources/App/routes.swift
Normal file
@@ -0,0 +1,20 @@
|
||||
import Vapor
|
||||
|
||||
// Register your application's routes here.
|
||||
public func routes(_ app: Application) throws {
|
||||
app.get("") { req async throws -> View in
|
||||
return try await req.view.render("home")
|
||||
}
|
||||
app.get("index.html") { req async throws -> View in
|
||||
return try await req.view.render("home")
|
||||
}
|
||||
app.get("privacy") { req async throws -> View in
|
||||
return try await req.view.render("privacy")
|
||||
}
|
||||
app.get("welcome") { req async throws -> View in
|
||||
return try await req.view.render("welcome")
|
||||
}
|
||||
app.get("**") { req async throws -> View in
|
||||
return try await req.view.render("404")
|
||||
}
|
||||
}
|
||||
9
Sources/Run/main.swift
Normal file
9
Sources/Run/main.swift
Normal file
@@ -0,0 +1,9 @@
|
||||
import App
|
||||
import Vapor
|
||||
|
||||
var env = try Environment.detect()
|
||||
try LoggingSystem.bootstrap(from: &env)
|
||||
let app = Application(env)
|
||||
defer { app.shutdown() }
|
||||
try configure(app)
|
||||
try app.run()
|
||||
Reference in New Issue
Block a user