@telorun/http-server 0.15.0 → 0.15.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @telorun/http-server
2
2
 
3
+ ## 0.15.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 06c675b: Fix CORS preflight returning 404. `Http.Server` forwarded every `cors` option to `@fastify/cors`, including the ones the manifest left unset — spreading `preflight: undefined` (and friends) clobbered the plugin's own default `preflight: true`, so its `OPTIONS *` handler `callNotFound()`'d and the preflight came back 404. Browsers reject that ("Response to preflight request … does not have HTTP ok status") and block every cross-origin `POST`. Now only the fields actually set on `cors` are passed through, so unset options keep the plugin's defaults and preflight replies 204.
8
+
3
9
  ## 0.15.0
4
10
 
5
11
  ### Minor Changes
@@ -73,20 +73,31 @@ class HttpServer {
73
73
  }
74
74
  }
75
75
  if (this.resource.cors) {
76
- await this.app.register(cors, {
77
- origin: this.resource.cors.origin,
78
- methods: this.resource.cors.methods,
79
- allowedHeaders: this.resource.cors.allowedHeaders,
80
- exposedHeaders: this.resource.cors.exposedHeaders,
81
- credentials: this.resource.cors.credentials,
82
- maxAge: this.resource.cors.maxAge,
83
- cacheControl: this.resource.cors.cacheControl,
84
- preflightContinue: this.resource.cors.preflightContinue,
85
- optionsSuccessStatus: this.resource.cors.optionsSuccessStatus,
86
- preflight: this.resource.cors.preflight,
87
- strictPreflight: this.resource.cors.strictPreflight,
88
- hideOptionsRoute: this.resource.cors.hideOptionsRoute,
89
- });
76
+ // Only forward the fields the manifest actually set. Spreading `undefined`
77
+ // for an unset option overrides @fastify/cors's own defaults with
78
+ // `undefined` — notably `preflight: undefined` disables the preflight 204
79
+ // reply (its `OPTIONS *` handler then `callNotFound()`s → 404), which a
80
+ // browser reports as "preflight … does not have HTTP ok status".
81
+ const cfg = this.resource.cors;
82
+ const corsOptions = {};
83
+ for (const key of [
84
+ "origin",
85
+ "methods",
86
+ "allowedHeaders",
87
+ "exposedHeaders",
88
+ "credentials",
89
+ "maxAge",
90
+ "cacheControl",
91
+ "preflightContinue",
92
+ "optionsSuccessStatus",
93
+ "preflight",
94
+ "strictPreflight",
95
+ "hideOptionsRoute",
96
+ ]) {
97
+ if (cfg[key] !== undefined)
98
+ corsOptions[key] = cfg[key];
99
+ }
100
+ await this.app.register(cors, corsOptions);
90
101
  }
91
102
  // Register custom error handler for validation errors
92
103
  this.app.setErrorHandler((error, request, reply) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telorun/http-server",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
4
4
  "description": "Telo HTTP Server module - HTTP server and API resource kinds for Telo manifests.",
5
5
  "keywords": [
6
6
  "telo",
@@ -155,20 +155,30 @@ class HttpServer implements ResourceInstance {
155
155
  }
156
156
 
157
157
  if (this.resource.cors) {
158
- await this.app.register(cors, {
159
- origin: this.resource.cors.origin,
160
- methods: this.resource.cors.methods,
161
- allowedHeaders: this.resource.cors.allowedHeaders,
162
- exposedHeaders: this.resource.cors.exposedHeaders,
163
- credentials: this.resource.cors.credentials,
164
- maxAge: this.resource.cors.maxAge,
165
- cacheControl: this.resource.cors.cacheControl,
166
- preflightContinue: this.resource.cors.preflightContinue,
167
- optionsSuccessStatus: this.resource.cors.optionsSuccessStatus,
168
- preflight: this.resource.cors.preflight,
169
- strictPreflight: this.resource.cors.strictPreflight,
170
- hideOptionsRoute: this.resource.cors.hideOptionsRoute,
171
- });
158
+ // Only forward the fields the manifest actually set. Spreading `undefined`
159
+ // for an unset option overrides @fastify/cors's own defaults with
160
+ // `undefined` — notably `preflight: undefined` disables the preflight 204
161
+ // reply (its `OPTIONS *` handler then `callNotFound()`s → 404), which a
162
+ // browser reports as "preflight … does not have HTTP ok status".
163
+ const cfg = this.resource.cors;
164
+ const corsOptions: Record<string, unknown> = {};
165
+ for (const key of [
166
+ "origin",
167
+ "methods",
168
+ "allowedHeaders",
169
+ "exposedHeaders",
170
+ "credentials",
171
+ "maxAge",
172
+ "cacheControl",
173
+ "preflightContinue",
174
+ "optionsSuccessStatus",
175
+ "preflight",
176
+ "strictPreflight",
177
+ "hideOptionsRoute",
178
+ ] as const) {
179
+ if (cfg[key] !== undefined) corsOptions[key] = cfg[key];
180
+ }
181
+ await this.app.register(cors, corsOptions);
172
182
  }
173
183
 
174
184
  // Register custom error handler for validation errors