azurajs 3.0.7 → 3.0.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azurajs",
3
- "version": "3.0.7",
3
+ "version": "3.0.8",
4
4
  "description": "Ultra-fast TypeScript-first web framework for Node.js and Bun with decorator-based routing, zero dependencies, and built-in plugin system",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -22,6 +22,7 @@ import type { ControllerMetadata, RouteMeta, RouteMetadata } from "../types/rout
22
22
  import type { BuildOpenApiOptions } from "../types/swagger.type.js";
23
23
  import { API_OPERATION_KEY, API_TAGS_KEY, METHOD_TAGS_KEY } from "../swagger/constants.js";
24
24
  import { buildOpenApiDocument } from "../swagger/openapi-builder.js";
25
+ import { CORSPlugin } from "../plugins/CORSPlugin.js";
25
26
 
26
27
  function isRouteDocumentMeta(o: unknown): o is RouteMeta {
27
28
  if (!o || typeof o !== "object" || Array.isArray(o)) return false;
@@ -82,6 +83,17 @@ export class AzuraServer {
82
83
  colors: this.config.logging?.colors,
83
84
  timestamp: this.config.logging?.timestamp,
84
85
  });
86
+
87
+ this.registerPluginsFromConfig();
88
+ }
89
+
90
+ /** Activa plugins declarados em `config.plugins` (ex.: CORS). */
91
+ private registerPluginsFromConfig(): void {
92
+ const corsCfg = this.config.plugins?.cors;
93
+ if (corsCfg && corsCfg.enabled !== false) {
94
+ const { enabled: _e, ...corsOptions } = corsCfg;
95
+ this.plugins.push(CORSPlugin(corsOptions));
96
+ }
85
97
  }
86
98
 
87
99
  use(handler: MiddlewareHandler | PluginHandler): this {
@@ -457,7 +469,7 @@ export class AzuraServer {
457
469
  const chain = this.compileMiddlewareChain();
458
470
  await chain(azReq, azRes);
459
471
 
460
- if (azRes.sent) return;
472
+ if (azRes.sent || res.headersSent) return;
461
473
 
462
474
  const method = (req.method ?? "GET").toUpperCase() as HttpMethod;
463
475
  const match = this.router.find(method, pathname);
@@ -1,3 +1,4 @@
1
+ import type { AzuraResponse } from "../types/common.type.js";
1
2
  import type { CORSOptions, PluginHandler } from "../types/plugins/plugin.type.js";
2
3
 
3
4
  const DEFAULT_METHODS = ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"];
@@ -45,6 +46,7 @@ export function CORSPlugin(options: CORSOptions = {}): PluginHandler {
45
46
  res.setHeader("Access-Control-Max-Age", String(maxAge));
46
47
 
47
48
  if (!preflightContinue) {
49
+ (res as AzuraResponse).sent = true;
48
50
  res.statusCode = 204;
49
51
  res.end();
50
52
  return;