Skip to content

Commit c434ff4

Browse files
committed
Updated Leaf cache & Chapter 10 [wip]
1 parent d66e4a3 commit c434ff4

File tree

35 files changed

+146
-256
lines changed

35 files changed

+146
-256
lines changed

Chapter 03/myProject/Package.resolved

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Chapter 03/myProject/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let package = Package(
1010
// 💧 A server-side Swift web framework.
1111
.package(url: "https://github.com/vapor/vapor", from: "4.32.0"),
1212
//.package(url: "https://github.com/vapor/leaf", from: "4.0.0"),
13-
.package(url: "https://github.com/tib/leaf", .branch("tau")),
13+
.package(url: "https://github.com/tib/leaf", from: "4.0.0-rc"),
1414
.package(url: "https://github.com/lukaskubanek/LoremSwiftum", from: "2.2.1")
1515
],
1616
targets: [

Chapter 03/myProject/Sources/App/Middlewares/DropLeafCacheMiddleware.swift

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Tibor Bodecs on 2020. 10. 14..
6+
//
7+
8+
import Vapor
9+
10+
struct ExtendPathMiddleware: Middleware {
11+
12+
func respond(to request: Request, chainingTo next: Responder) -> EventLoopFuture<Response> {
13+
if !request.url.path.hasSuffix("/") {
14+
let response = request.redirect(to: request.url.path + "/", type: .permanent)
15+
return request.eventLoop.makeSucceededFuture(response)
16+
}
17+
return next.respond(to: request)
18+
}
19+
}

Chapter 03/myProject/Sources/App/Modules/Blog/BlogPost.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Foundation
12
import Leaf
23

34
struct BlogPost {

Chapter 03/myProject/Sources/App/configure.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import Leaf
44
public func configure(_ app: Application) throws {
55

66
app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
7-
7+
app.middleware.use(ExtendPathMiddleware())
8+
89
let detected = LeafEngine.rootDirectory ?? app.directory.viewsDirectory
910
LeafEngine.rootDirectory = detected
1011

@@ -15,10 +16,11 @@ public func configure(_ app: Application) throws {
1516
defaultExtension: "html"))
1617

1718
if !app.environment.isRelease {
18-
app.middleware.use(DropLeafCacheMiddleware())
19+
LeafRenderer.Option.caching = .bypass
1920
}
21+
2022
app.views.use(.leaf)
21-
23+
2224
let routers: [RouteCollection] = [
2325
FrontendRouter(),
2426
BlogRouter(),

Chapter 04/myProject/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let package = Package(
1010
// 💧 A server-side Swift web framework.
1111
.package(url: "https://github.com/vapor/vapor", from: "4.32.0"),
1212
//.package(url: "https://github.com/vapor/leaf", from: "4.0.0"),
13-
.package(url: "https://github.com/tib/leaf", .branch("tau")),
13+
.package(url: "https://github.com/tib/leaf", from: "4.0.0-rc"),
1414
.package(url: "https://github.com/vapor/fluent", from: "4.0.0"),
1515
.package(url: "https://github.com/vapor/fluent-sqlite-driver", from: "4.0.0"),
1616
.package(url: "https://github.com/lukaskubanek/LoremSwiftum", from: "2.2.1"),

Chapter 04/myProject/Sources/App/Middlewares/DropLeafCacheMiddleware.swift

Lines changed: 0 additions & 19 deletions
This file was deleted.

Chapter 04/myProject/Sources/App/configure.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public func configure(_ app: Application) throws {
1919
defaultExtension: "html"))
2020

2121
if !app.environment.isRelease {
22-
app.middleware.use(DropLeafCacheMiddleware())
22+
LeafRenderer.Option.caching = .bypass
2323
}
2424
app.views.use(.leaf)
2525

Chapter 05/myProject/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let package = Package(
1010
// 💧 A server-side Swift web framework.
1111
.package(url: "https://github.com/vapor/vapor", from: "4.32.0"),
1212
//.package(url: "https://github.com/vapor/leaf", from: "4.0.0"),
13-
.package(url: "https://github.com/tib/leaf", .branch("tau")),
13+
.package(url: "https://github.com/tib/leaf", from: "4.0.0-rc"),
1414
.package(url: "https://github.com/vapor/fluent", from: "4.0.0"),
1515
.package(url: "https://github.com/vapor/fluent-sqlite-driver", from: "4.0.0"),
1616
.package(url: "https://github.com/lukaskubanek/LoremSwiftum", from: "2.2.1"),

0 commit comments

Comments
 (0)