starlight-server 1.9.2 → 1.9.3

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/http/cors.js CHANGED
@@ -11,7 +11,7 @@ export function isPreflight(request) {
11
11
  * 否则返回 null
12
12
  */
13
13
  export function getPreflightRequestMethod(request) {
14
- return isPreflight(request) ? request.headers['access-control-request-method'] ?? '' : null;
14
+ return isPreflight(request) ? (request.headers['access-control-request-method'] ?? '') : null;
15
15
  }
16
16
  /**
17
17
  * 输出 CORS 相关 headers
@@ -60,6 +60,7 @@ export class ResponseUtils {
60
60
  error(error) {
61
61
  if (error instanceof HTTPError) {
62
62
  this.nodeResponse.statusCode = error.status;
63
+ this.nodeResponse.setHeader('Content-Type', 'text/plain; charset=UTF-8');
63
64
  this.nodeResponse.end(error.message);
64
65
  }
65
66
  else if (typeof error === 'number') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-server",
3
- "version": "1.9.2",
3
+ "version": "1.9.3",
4
4
  "description": "Simple But Powerful Node.js HTTP Server",
5
5
  "type": "module",
6
6
  "keywords": [
package/src/http/cors.ts CHANGED
@@ -20,7 +20,7 @@ export function isPreflight(request: Request | NodeRequest) {
20
20
  * 否则返回 null
21
21
  */
22
22
  export function getPreflightRequestMethod(request: Request | NodeRequest) {
23
- return isPreflight(request) ? request.headers['access-control-request-method'] ?? '' : null
23
+ return isPreflight(request) ? (request.headers['access-control-request-method'] ?? '') : null
24
24
  }
25
25
 
26
26
  /**
@@ -64,6 +64,7 @@ export class ResponseUtils {
64
64
  error(error: unknown) {
65
65
  if (error instanceof HTTPError) {
66
66
  this.nodeResponse.statusCode = error.status
67
+ this.nodeResponse.setHeader('Content-Type', 'text/plain; charset=UTF-8')
67
68
  this.nodeResponse.end(error.message)
68
69
  } else if (typeof error === 'number') {
69
70
  this.error(new HTTPError(error))
@@ -128,6 +128,7 @@ export class Router {
128
128
  response.nodeResponse.end('')
129
129
  return
130
130
  }
131
+
131
132
  throw new HTTPError(405) // 有路径匹配的路由,但是没有 method 匹配的
132
133
  } else {
133
134
  const corsRule = matched.route.cors ?? this.cors