@tatara/http 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -64,8 +64,11 @@ type Defaults<E extends HttpEnv> = Partial<Omit<E["Variables"], "requestId" | "l
64
64
  export declare function requestContext<E extends HttpEnv>(logger: CoreLogger, defaults?: Defaults<E>): MiddlewareHandler<E, string, {}, Response>;
65
65
  interface CreateAppOptions<E extends HttpEnv> {
66
66
  logger: CoreLogger;
67
- /** origins are exact (`https://app.example.com`) or one-label patterns (`https://*.example.com`) */
68
- cors: {
67
+ /**
68
+ * Deprecated: call Hono's `cors()` in the app instead (with `corsOrigin` for the origin check),
69
+ * so its headers and origins are the app's. Kept so existing apps keep working.
70
+ */
71
+ cors?: {
69
72
  origins: string[];
70
73
  exposeHeaders?: string[];
71
74
  allowHeaders?: string[];
@@ -78,7 +81,7 @@ interface CreateAppOptions<E extends HttpEnv> {
78
81
  }
79
82
  /** Matches exact origins and `*.`-patterns, where `*` is exactly one DNS label (tenant subdomains). */
80
83
  export declare function corsOrigin(origins: string[]): (origin: string) => string | null;
81
- /** A plain OpenAPIHono app with request context, secure headers, CORS, body limit, /health and /ready. */
84
+ /** A plain OpenAPIHono app with request context, secure headers, body limit, /health and /ready. CORS is the app's: Hono's `cors()`. */
82
85
  export declare function createApp<E extends HttpEnv>(options: CreateAppOptions<E>): OpenAPIHono<E>;
83
86
  interface RouteDefinition<A extends string = string, E extends HttpEnv = HttpEnv> {
84
87
  /** which HTTP app serves these routes */
package/dist/index.mjs CHANGED
@@ -145,12 +145,12 @@ function corsOrigin(origins) {
145
145
  });
146
146
  return (origin) => exact.has(origin) || patterns.some((p) => p.test(origin)) ? origin : null;
147
147
  }
148
- /** A plain OpenAPIHono app with request context, secure headers, CORS, body limit, /health and /ready. */
148
+ /** A plain OpenAPIHono app with request context, secure headers, body limit, /health and /ready. CORS is the app's: Hono's `cors()`. */
149
149
  function createApp(options) {
150
150
  const app = new OpenAPIHono({ defaultHook: validationHook });
151
151
  app.use(requestContext(options.logger, options.defaults));
152
152
  app.use(secureHeaders());
153
- app.use(cors({
153
+ if (options.cors) app.use(cors({
154
154
  origin: corsOrigin(options.cors.origins),
155
155
  credentials: true,
156
156
  allowHeaders: options.cors.allowHeaders ?? [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tatara/http",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "tatara HTTP: Hono app setup, errors, envelope, OpenAPI docs and route mounting",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -31,7 +31,7 @@
31
31
  "@hono/zod-openapi": "^1.6.3",
32
32
  "@hono/node-server": "^2.1.5",
33
33
  "@scalar/hono-api-reference": "^0.12.12",
34
- "@tatara/core": "^0.1.2",
34
+ "@tatara/core": "^0.1.3",
35
35
  "pino": "^10.4.0",
36
36
  "zod": "^4.6.7"
37
37
  },
package/src/app.ts CHANGED
@@ -43,8 +43,11 @@ export function requestContext<E extends HttpEnv>(logger: CoreLogger, defaults:
43
43
 
44
44
  export interface CreateAppOptions<E extends HttpEnv> {
45
45
  logger: CoreLogger;
46
- /** origins are exact (`https://app.example.com`) or one-label patterns (`https://*.example.com`) */
47
- cors: { origins: string[]; exposeHeaders?: string[]; allowHeaders?: string[] };
46
+ /**
47
+ * Deprecated: call Hono's `cors()` in the app instead (with `corsOrigin` for the origin check),
48
+ * so its headers and origins are the app's. Kept so existing apps keep working.
49
+ */
50
+ cors?: { origins: string[]; exposeHeaders?: string[]; allowHeaders?: string[] };
48
51
  bodyLimitBytes: number;
49
52
  /** a limit on how long a handler may take, with longer ones for slow paths */
50
53
  timeouts?: TimeoutOptions;
@@ -66,24 +69,25 @@ export function corsOrigin(origins: string[]): (origin: string) => string | null
66
69
  return (origin) => (exact.has(origin) || patterns.some((p) => p.test(origin)) ? origin : null);
67
70
  }
68
71
 
69
- /** A plain OpenAPIHono app with request context, secure headers, CORS, body limit, /health and /ready. */
72
+ /** A plain OpenAPIHono app with request context, secure headers, body limit, /health and /ready. CORS is the app's: Hono's `cors()`. */
70
73
  export function createApp<E extends HttpEnv>(options: CreateAppOptions<E>): OpenAPIHono<E> {
71
74
  const app = new OpenAPIHono<E>({ defaultHook: validationHook });
72
75
  app.use(requestContext<E>(options.logger, options.defaults) as MiddlewareHandler<E>);
73
76
  app.use(secureHeaders());
74
- app.use(
75
- cors({
76
- origin: corsOrigin(options.cors.origins),
77
- credentials: true,
78
- allowHeaders: options.cors.allowHeaders ?? [
79
- "Content-Type",
80
- "Authorization",
81
- "X-Request-Id",
82
- "Accept-Language",
83
- ],
84
- exposeHeaders: options.cors.exposeHeaders ?? ["X-Request-Id"],
85
- }),
86
- );
77
+ if (options.cors)
78
+ app.use(
79
+ cors({
80
+ origin: corsOrigin(options.cors.origins),
81
+ credentials: true,
82
+ allowHeaders: options.cors.allowHeaders ?? [
83
+ "Content-Type",
84
+ "Authorization",
85
+ "X-Request-Id",
86
+ "Accept-Language",
87
+ ],
88
+ exposeHeaders: options.cors.exposeHeaders ?? ["X-Request-Id"],
89
+ }),
90
+ );
87
91
  app.use(bodyLimit({ maxSize: options.bodyLimitBytes }));
88
92
  if (options.timeouts) app.use(requestTimeout(options.timeouts));
89
93
  app.get("/health", (c) => c.json({ status: "ok" }));