dsShelfApiKeyMiddleware function

Middleware dsShelfApiKeyMiddleware(
  1. String expectedKey
)

Simple API key check middleware.

Implementation

Middleware dsShelfApiKeyMiddleware(String expectedKey) {
  return (Handler inner) {
    return (Request request) async {
      final apiKey = request.headers['x-api-key'];
      if (apiKey != expectedKey) {
        return Response.forbidden('Invalid API key');
      }
      return await inner(request);
    };
  };
}