Kept the prototype out of search engines in the Website service.

This commit is contained in:
javier committed 2026-09-21 17:36:39 +02:00
1 parent 359fe0d6ac
commit 326299fc35
12 files changed
+232 -44

No files matched your search

@@ -0,0 +1,43 @@
import Hummingbird
import Infrastructure
/// Keeps the site out of search engines: every response — pages, files, redirects, errors — is marked `X-Robots-Tag: noindex, nofollow`.
///
/// A header rather than `robots.txt`, which stays open on purpose: a crawler barred from a page never reads its `noindex`, and may still
/// list the bare URL from links elsewhere. A header also covers what carries no markup, such as the photos sellers upload.
public struct NoIndexMiddleware<Context: RequestContext>: RouterMiddleware {
// MARK: Constants
/// The directive stamped on every response.
public static var directive: String { "noindex, nofollow" }
// MARK: Initializers
/// Creates the middleware.
public init() {}
// MARK: Methods
public func handle(
_ request: Request,
context: Context,
next: (Request, Context) async throws -> Response
) async throws -> Response {
do {
var response = try await next(request, context)
response.headers[.robotsTag] = Self.directive
return response
} catch let error as HTTPError {
// An error thrown past this point becomes a response further out: the mark travels with it.
var error = error
error.headers[.robotsTag] = Self.directive
throw error
}
}
}