Created a new project using toolbox command: vapor new projectname
In main.swift file I added the middleware code:
import Vapor
import HTTP
final class VersionMiddleware: Middleware {
func respond(to request: Request, chainingTo next: Responder) throws -> Response {
let response = try next.respond(to: request)
response.headers["Version"] = "API v1.0"
print("not printing")
return response
}
}
let drop = Droplet(availableMiddleware: [
"version": VersionMiddleware()
])
drop.get("hello") {
req in
return "Hello world"
}
drop.run()
But when I run this, it prints "hello world" but the API version is not added to headers. I am checking it using postman.