@radatek/microserver 2.3.9 → 2.3.10
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/microserver.d.ts +4 -2
- package/microserver.js +6 -6
- package/package.json +1 -1
package/microserver.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* MicroServer
|
|
3
|
-
* @version 2.3.
|
|
3
|
+
* @version 2.3.10
|
|
4
4
|
* @package @radatek/microserver
|
|
5
5
|
* @copyright Darius Kisonas 2022
|
|
6
6
|
* @license MIT
|
|
@@ -120,7 +120,7 @@ export declare class ServerResponse<T = any> extends http.ServerResponse {
|
|
|
120
120
|
redirect(code: number | string, url?: string): void;
|
|
121
121
|
/** Set status code */
|
|
122
122
|
status(code: number): this;
|
|
123
|
-
|
|
123
|
+
file(path: string, filename?: string): void;
|
|
124
124
|
}
|
|
125
125
|
/** WebSocket options */
|
|
126
126
|
export interface WebSocketOptions {
|
|
@@ -551,6 +551,8 @@ export interface AuthOptionsInternal extends AuthOptions {
|
|
|
551
551
|
};
|
|
552
552
|
/** Expire time in seconds */
|
|
553
553
|
expire: number;
|
|
554
|
+
/** Use object token instead of user id */
|
|
555
|
+
objectToken: boolean;
|
|
554
556
|
/** Authentication mode */
|
|
555
557
|
mode: 'cookie' | 'token';
|
|
556
558
|
/** Authentication realm for basic authentication */
|
package/microserver.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* MicroServer
|
|
3
|
-
* @version 2.3.
|
|
3
|
+
* @version 2.3.10
|
|
4
4
|
* @package @radatek/microserver
|
|
5
5
|
* @copyright Darius Kisonas 2022
|
|
6
6
|
* @license MIT
|
|
@@ -438,7 +438,7 @@ export class ServerResponse extends http.ServerResponse {
|
|
|
438
438
|
this.statusCode = code;
|
|
439
439
|
return this;
|
|
440
440
|
}
|
|
441
|
-
|
|
441
|
+
file(path, filename) {
|
|
442
442
|
StaticPlugin.serveFile(this.req, this, {
|
|
443
443
|
path: path,
|
|
444
444
|
filename: filename || basename(path),
|
|
@@ -987,7 +987,7 @@ export class Router extends EventEmitter {
|
|
|
987
987
|
idx = 5;
|
|
988
988
|
}
|
|
989
989
|
if (name === 'json')
|
|
990
|
-
return (req, res) => res.isJson = true;
|
|
990
|
+
return (req, res, next) => { res.isJson = true; return next(); };
|
|
991
991
|
if (idx >= 0) {
|
|
992
992
|
const v = name.slice(idx + 1);
|
|
993
993
|
const type = name.slice(0, idx);
|
|
@@ -2109,7 +2109,7 @@ export class Auth {
|
|
|
2109
2109
|
if (usrInfo?.id || usrInfo?._id) {
|
|
2110
2110
|
const expire = Math.min(34560000, options?.expire || this.options.expire || defaultExpire);
|
|
2111
2111
|
const expireTime = new Date().getTime() + expire * 1000;
|
|
2112
|
-
const token = await this.token((usrInfo?.id || usrInfo?._id), undefined, expire);
|
|
2112
|
+
const token = await this.token(this.options.objectToken ? JSON.stringify(usrInfo) : (usrInfo?.id || usrInfo?._id), undefined, expire);
|
|
2113
2113
|
if (token && this.res && this.req) {
|
|
2114
2114
|
const oldToken = this.req.tokenId;
|
|
2115
2115
|
if (oldToken)
|
|
@@ -2313,14 +2313,14 @@ class AuthPlugin extends Plugin {
|
|
|
2313
2313
|
}
|
|
2314
2314
|
return next();
|
|
2315
2315
|
}
|
|
2316
|
-
const cookie = req.headers.cookie, cookies = cookie ? cookie.split(/;\s
|
|
2316
|
+
const cookie = req.headers.cookie, cookies = cookie ? cookie.split(/;\s*/g) : [];
|
|
2317
2317
|
const sid = cookies.find(s => s.startsWith('token='));
|
|
2318
2318
|
let token = '';
|
|
2319
2319
|
if (authorization.startsWith('Bearer '))
|
|
2320
2320
|
token = authorization.slice(7);
|
|
2321
2321
|
if (sid)
|
|
2322
2322
|
token = sid.slice(sid.indexOf('=') + 1);
|
|
2323
|
-
if (
|
|
2323
|
+
if (req.query.token)
|
|
2324
2324
|
token = req.query.token;
|
|
2325
2325
|
if (token) {
|
|
2326
2326
|
const now = new Date().getTime();
|