@yumerijs/core 2.0.5 → 2.0.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.
package/dist/server.js CHANGED
@@ -118,34 +118,36 @@ class Server {
118
118
  this.serveStaticFile(pathname, res);
119
119
  }
120
120
  else {
121
- let head = session.head;
122
- head['Set-Cookie'] = Object.entries(session.newCookie).map(([name, cookie]) => {
123
- let cookieString = `${name}=${cookie.value}`;
124
- if (cookie.options.expires) {
125
- cookieString += `; Expires=${cookie.options.expires.toUTCString()}`;
121
+ if (!session.responseHandled) {
122
+ let head = session.head;
123
+ head['Set-Cookie'] = Object.entries(session.newCookie).map(([name, cookie]) => {
124
+ let cookieString = `${name}=${cookie.value}`;
125
+ if (cookie.options.expires) {
126
+ cookieString += `; Expires=${cookie.options.expires.toUTCString()}`;
127
+ }
128
+ if (cookie.options.path) {
129
+ cookieString += `; Path=${cookie.options.path}`;
130
+ }
131
+ if (cookie.options.domain) {
132
+ cookieString += `; Domain=${cookie.options.domain}`;
133
+ }
134
+ if (cookie.options.secure) {
135
+ cookieString += `; Secure`;
136
+ }
137
+ if (cookie.options.httpOnly) {
138
+ cookieString += `; HttpOnly`;
139
+ }
140
+ if (cookie.options.sameSite) {
141
+ cookieString += `; SameSite=${cookie.options.sameSite}`;
142
+ }
143
+ return cookieString;
144
+ });
145
+ if (this.enableCors) {
146
+ head['Access-Control-Allow-Origin'] = '*';
126
147
  }
127
- if (cookie.options.path) {
128
- cookieString += `; Path=${cookie.options.path}`;
129
- }
130
- if (cookie.options.domain) {
131
- cookieString += `; Domain=${cookie.options.domain}`;
132
- }
133
- if (cookie.options.secure) {
134
- cookieString += `; Secure`;
135
- }
136
- if (cookie.options.httpOnly) {
137
- cookieString += `; HttpOnly`;
138
- }
139
- if (cookie.options.sameSite) {
140
- cookieString += `; SameSite=${cookie.options.sameSite}`;
141
- }
142
- return cookieString;
143
- });
144
- if (this.enableCors) {
145
- head['Access-Control-Allow-Origin'] = '*';
148
+ res.writeHead(session.status ?? 200, head);
149
+ res.end(session.body);
146
150
  }
147
- res.writeHead(session.status ?? 200, head);
148
- res.end(session.body);
149
151
  }
150
152
  }
151
153
  else if (rootroute && rootroute.allowedMethods.includes(req.method ?? 'GET')) {
@@ -154,34 +156,36 @@ class Server {
154
156
  this.serveStaticFile(pathname, res);
155
157
  }
156
158
  else {
157
- let head = session.head;
158
- head['Set-Cookie'] = Object.entries(session.newCookie).map(([name, cookie]) => {
159
- let cookieString = `${name}=${cookie.value}`;
160
- if (cookie.options.expires) {
161
- cookieString += `; Expires=${cookie.options.expires.toUTCString()}`;
159
+ if (!session.responseHandled) {
160
+ let head = session.head;
161
+ head['Set-Cookie'] = Object.entries(session.newCookie).map(([name, cookie]) => {
162
+ let cookieString = `${name}=${cookie.value}`;
163
+ if (cookie.options.expires) {
164
+ cookieString += `; Expires=${cookie.options.expires.toUTCString()}`;
165
+ }
166
+ if (cookie.options.path) {
167
+ cookieString += `; Path=${cookie.options.path}`;
168
+ }
169
+ if (cookie.options.domain) {
170
+ cookieString += `; Domain=${cookie.options.domain}`;
171
+ }
172
+ if (cookie.options.secure) {
173
+ cookieString += `; Secure`;
174
+ }
175
+ if (cookie.options.httpOnly) {
176
+ cookieString += `; HttpOnly`;
177
+ }
178
+ if (cookie.options.sameSite) {
179
+ cookieString += `; SameSite=${cookie.options.sameSite}`;
180
+ }
181
+ return cookieString;
182
+ });
183
+ if (this.enableCors) {
184
+ head['Access-Control-Allow-Origin'] = '*';
162
185
  }
163
- if (cookie.options.path) {
164
- cookieString += `; Path=${cookie.options.path}`;
165
- }
166
- if (cookie.options.domain) {
167
- cookieString += `; Domain=${cookie.options.domain}`;
168
- }
169
- if (cookie.options.secure) {
170
- cookieString += `; Secure`;
171
- }
172
- if (cookie.options.httpOnly) {
173
- cookieString += `; HttpOnly`;
174
- }
175
- if (cookie.options.sameSite) {
176
- cookieString += `; SameSite=${cookie.options.sameSite}`;
177
- }
178
- return cookieString;
179
- });
180
- if (this.enableCors) {
181
- head['Access-Control-Allow-Origin'] = '*';
186
+ res.writeHead(session.status ?? 200, head);
187
+ res.end(session.body);
182
188
  }
183
- res.writeHead(session.status ?? 200, head);
184
- res.end(session.body);
185
189
  }
186
190
  }
187
191
  else {
package/dist/session.d.ts CHANGED
@@ -38,6 +38,7 @@ export declare class Session {
38
38
  protocol: string;
39
39
  pathname: string;
40
40
  languages: string[];
41
+ responseHandled: boolean;
41
42
  /**
42
43
  * @constructor
43
44
  * @param ip 用户IP
package/dist/session.js CHANGED
@@ -60,6 +60,7 @@ class Session {
60
60
  protocol = 'http';
61
61
  pathname;
62
62
  languages;
63
+ responseHandled = false;
63
64
  /**
64
65
  * @constructor
65
66
  * @param ip 用户IP
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yumerijs/core",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
4
4
  "description": "Core module for yumeri",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",