starlight-server 1.6.5 → 1.6.6

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.
@@ -15,6 +15,7 @@ export declare class ResponseUtils {
15
15
  jsonReplacer?: ((key: string, value: unknown) => unknown) | undefined);
16
16
  header(name: string, value: string): void;
17
17
  headers(...items: [string, string][]): void;
18
+ headers(items: Record<string, string>): void;
18
19
  text(content: string | Buffer): void;
19
20
  /**
20
21
  * Output JSON
@@ -19,7 +19,10 @@ export class ResponseUtils {
19
19
  this.nodeResponse.setHeader(name, value);
20
20
  }
21
21
  headers(...items) {
22
- items.forEach(([name, value]) => this.header(name, value));
22
+ if (items.length === 1 && typeof items[0] === 'object') {
23
+ items = Object.entries(items[0]);
24
+ }
25
+ void items.forEach(([name, value]) => this.header(name, value));
23
26
  }
24
27
  text(content) {
25
28
  this.nodeResponse.end(content);
@@ -95,6 +95,10 @@ export class Router {
95
95
  }
96
96
  throw new HTTPError(405); // 有路径匹配的路由,但是没有 method 匹配的
97
97
  }
98
+ else {
99
+ const corsRule = matched.route.cors ?? this.cors;
100
+ handleCORS(request, response, typeof corsRule === 'function' ? corsRule(request) : corsRule);
101
+ }
98
102
  const basicContext = {};
99
103
  const helpers = new Helpers(basicContext);
100
104
  Object.assign(basicContext, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-server",
3
- "version": "1.6.5",
3
+ "version": "1.6.6",
4
4
  "description": "Simple But Powerful Node.js HTTP Server",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -18,8 +18,13 @@ export class ResponseUtils {
18
18
  this.nodeResponse.setHeader(name, value)
19
19
  }
20
20
 
21
- headers(...items: [string, string][]) {
22
- items.forEach(([name, value]) => this.header(name, value))
21
+ headers(...items: [string, string][]): void
22
+ headers(items: Record<string, string>): void
23
+ headers(...items: [string, string][] | [Record<string, string>]) {
24
+ if (items.length === 1 && typeof items[0] === 'object') {
25
+ items = Object.entries(items[0] as Record<string, string>)
26
+ }
27
+ void (items as [string, string][]).forEach(([name, value]) => this.header(name, value))
23
28
  }
24
29
 
25
30
  text(content: string | Buffer) {
@@ -131,6 +131,9 @@ export class Router {
131
131
  return
132
132
  }
133
133
  throw new HTTPError(405) // 有路径匹配的路由,但是没有 method 匹配的
134
+ } else {
135
+ const corsRule = matched.route.cors ?? this.cors
136
+ handleCORS(request, response, typeof corsRule === 'function' ? corsRule(request) : corsRule)
134
137
  }
135
138
 
136
139
  const basicContext = {} as BasicContext