@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 +6 -0
- package/dist/http-server-controller.js +25 -14
- package/package.json +1 -1
- package/src/http-server-controller.ts +24 -14
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
@@ -155,20 +155,30 @@ class HttpServer implements ResourceInstance {
|
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
if (this.resource.cors) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|