File size: 731 Bytes
c09f67c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import type { Context, Next } from "hono";
import { env } from "hono/adapter";
import { bearerAuth } from "hono/bearer-auth";
import { logger } from "hono/logger";
import { secureHeaders } from "hono/secure-headers";
import { logger as customLogger } from "./utils/logger";

const PUBLIC_PATHS = ["/", "/openapi", "/health"];

const authMiddleware = (c: Context, next: Next) => {
  if (PUBLIC_PATHS.includes(c.req.path)) {
    return next();
  }

  const { API_SECRET_KEY } = env(c);

  const bearer = bearerAuth({ token: API_SECRET_KEY });

  return bearer(c, next);
};

const securityMiddleware = secureHeaders();
const loggingMiddleware = logger(customLogger);

export { authMiddleware, securityMiddleware, loggingMiddleware };