Creating this topic to catch any typos and bugs in the 3rd Edition Edition of Server-Side Swift with Vapor.
I hit a snag in Chapter 19 where a couple of tests werenāt passing. Specifically the testUpdatingAnAcronym()
and testAcronymCanBeSavedWithAPI()
tests were failing.
I discovered that it was due to the default password not being encrypted in the User.create(name:username:on)
extension method defined in Models+Testable.swift. To fix it I replaced this line:
let user = User(name: name, username: createUsername, password: "password")
with:
let user = User(name: name, username: createUsername, password: try Bcrypt.hash("password"))
I couldnāt find this change mentioned in the book (although I might have missed it). With this in place all tests are now .
@joltguy itās in the very first block of code in Chapter 19
Dāoh!!
I donāt know how I missed that! Itās like I typed in most of that block but somehow skipped the bottom part. Gahā¦ sorry about that. Thanks for pointing it out!
In Chapter 17, there is a sentence that has multiple ātoā which I think is a typo:
This is similar to to the existing CreateAcronymData
in AcronymsController.swift .
Thanks! Iāll get that fixed in the next update!
Hi Tim, I think that thereās a small typo in Chapter 8. On p111 of the PDF.
It states
Open AcronymsController.swift in Xcode and add the following to create an AcronymsController that conforms to RouteCollection:
import Vapor
import Fluent
struct AcronymsController: RouteCollection {
func boot(routes: RoutesBuilder) throws {
}
}
But then just over the page on p112 the next sentence states:
RouteCollection requires you to implement boot(router:) to register routes.
I assume that the ārouter:ā parameter is a hang-over from v3 of Vapor, and that the sentence should read:
RouteCollection requires you to implement boot(routes:) to register routes.
Similarly, I think that thereās some Vapor v3 code left in p114:
Next, open routes.swift and remove the remaining acronym route handlers:
ā¢ router.post("api", "acronyms")
ā¢ router.get("api", "acronyms", Acronym.parameter)
ā¢ router.put("api", "acronyms", Acronym.parameter)
ā¢ router.delete("api", "acronyms", Acronym.parameter)
ā¢ router.get("api", "acronyms", "search")
ā¢ router.get("api", "acronyms", "first")
ā¢ router.get("api", "acronyms", "sorted")
I suspect that should, instead, read:
ā¢app.post("api", "acronyms")
ā¢app.get("api", "acronyms", ":acronymID")
ā¢app.put("api", "acronyms", ":acronymID")
ā¢app.delete("api", "acronyms", ":acronymID")
ā¢app.get("api", "acronyms", "search")
ā¢app.get("api", "acronyms", "first")
ā¢app.get("api", "acronyms", "sorted")
And just under that:
Next, remove any other routes from the template. You should only have the AcronymsController registration left in routes(_:). Next, open AcronymsController.swift and recreate the handlers by adding each of the following after boot(router:)
s/router:/routes: again.
Thanks for spotting these! I suspect there was an errant merge somewhere. The fix should get merged and deployed soon