@e22m4u/js-http-static-router 0.1.0 → 0.1.2
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/README.md +5 -5
- package/dist/cjs/index.cjs +9 -9
- package/example/server.js +4 -4
- package/package.json +9 -9
- package/src/http-static-router.d.ts +1 -1
- package/src/http-static-router.js +10 -10
package/README.md
CHANGED
|
@@ -30,25 +30,25 @@ import {HttpStaticRouter} from '@e22m4u/js-http-static-router';
|
|
|
30
30
|
|
|
31
31
|
// создание экземпляра маршрутизатора
|
|
32
32
|
const staticRouter = new HttpStaticRouter({
|
|
33
|
-
// при использовании опции "
|
|
33
|
+
// при использовании опции "baseDir", относительные пути
|
|
34
34
|
// в регистрируемых маршрутах будут разрешаться относительно
|
|
35
35
|
// указанного адреса файловой системы
|
|
36
|
-
|
|
37
|
-
// в данном случае "
|
|
36
|
+
baseDir: import.meta.dirname,
|
|
37
|
+
// в данном случае "baseDir" указывает
|
|
38
38
|
// на путь к директории текущего модуля
|
|
39
39
|
});
|
|
40
40
|
// доступ к import.meta.dirname возможен
|
|
41
41
|
// только для ESM начиная с Node.js 20.11.0
|
|
42
42
|
|
|
43
43
|
// экспозиция содержимого директории "/static"
|
|
44
|
-
//
|
|
44
|
+
// для доступа по адресу "/assets/{file_name}"
|
|
45
45
|
staticRouter.defineRoute({
|
|
46
46
|
remotePath: '/assets', // путь маршрута
|
|
47
47
|
resourcePath: '../static', // файловый путь
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
// объявление файла "./index.html"
|
|
51
|
-
//
|
|
51
|
+
// для доступа по адресу "/home"
|
|
52
52
|
staticRouter.defineRoute({
|
|
53
53
|
remotePath: '/home',
|
|
54
54
|
resourcePath: './static/index.html',
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -200,17 +200,17 @@ var _HttpStaticRouter = class _HttpStaticRouter extends import_js_service.Debugg
|
|
|
200
200
|
options
|
|
201
201
|
);
|
|
202
202
|
}
|
|
203
|
-
if (options.
|
|
204
|
-
if (typeof options.
|
|
203
|
+
if (options.baseDir !== void 0) {
|
|
204
|
+
if (typeof options.baseDir !== "string") {
|
|
205
205
|
throw new import_js_format3.InvalidArgumentError(
|
|
206
|
-
'Option "
|
|
207
|
-
options.
|
|
206
|
+
'Option "baseDir" must be a String, but %v was given.',
|
|
207
|
+
options.baseDir
|
|
208
208
|
);
|
|
209
209
|
}
|
|
210
|
-
if (!import_path2.default.isAbsolute(options.
|
|
210
|
+
if (!import_path2.default.isAbsolute(options.baseDir)) {
|
|
211
211
|
throw new import_js_format3.InvalidArgumentError(
|
|
212
|
-
'Option "
|
|
213
|
-
options.
|
|
212
|
+
'Option "baseDir" must be an absolute path, but %v was given.',
|
|
213
|
+
options.baseDir
|
|
214
214
|
);
|
|
215
215
|
}
|
|
216
216
|
}
|
|
@@ -231,10 +231,10 @@ var _HttpStaticRouter = class _HttpStaticRouter extends import_js_service.Debugg
|
|
|
231
231
|
routeDef
|
|
232
232
|
);
|
|
233
233
|
}
|
|
234
|
-
if (this._options.
|
|
234
|
+
if (this._options.baseDir !== void 0 && !import_path2.default.isAbsolute(routeDef.resourcePath)) {
|
|
235
235
|
routeDef = { ...routeDef };
|
|
236
236
|
routeDef.resourcePath = import_path2.default.join(
|
|
237
|
-
this._options.
|
|
237
|
+
this._options.baseDir,
|
|
238
238
|
routeDef.resourcePath
|
|
239
239
|
);
|
|
240
240
|
}
|
package/example/server.js
CHANGED
|
@@ -3,21 +3,21 @@ import {HttpStaticRouter} from '@e22m4u/js-http-static-router';
|
|
|
3
3
|
|
|
4
4
|
// создание экземпляра маршрутизатора
|
|
5
5
|
const staticRouter = new HttpStaticRouter({
|
|
6
|
-
// при использовании опции "
|
|
6
|
+
// при использовании опции "baseDir", относительные пути
|
|
7
7
|
// в регистрируемых маршрутах будут разрешаться относительно
|
|
8
8
|
// указанного адреса файловой системы
|
|
9
|
-
|
|
9
|
+
baseDir: import.meta.dirname,
|
|
10
10
|
});
|
|
11
11
|
|
|
12
12
|
// экспозиция содержимого директории "/static"
|
|
13
|
-
//
|
|
13
|
+
// для доступа по адресу "/assets/{file_name}"
|
|
14
14
|
staticRouter.defineRoute({
|
|
15
15
|
remotePath: '/assets', // путь маршрута
|
|
16
16
|
resourcePath: './static', // файловый путь
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
// объявление файла "./index.html"
|
|
20
|
-
//
|
|
20
|
+
// для доступа по адресу "/home"
|
|
21
21
|
staticRouter.defineRoute({
|
|
22
22
|
remotePath: '/home',
|
|
23
23
|
resourcePath: './static/index.html',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e22m4u/js-http-static-router",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "HTTP-маршрутизатор статичных ресурсов для Node.js",
|
|
5
5
|
"author": "Mikhail Evstropov <e22m4u@yandex.ru>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,30 +37,30 @@
|
|
|
37
37
|
"prepare": "husky"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@e22m4u/js-format": "~0.
|
|
41
|
-
"@e22m4u/js-service": "~0.
|
|
40
|
+
"@e22m4u/js-format": "~0.4.0",
|
|
41
|
+
"@e22m4u/js-service": "~0.6.1",
|
|
42
42
|
"mime-types": "~3.0.2"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@commitlint/cli": "~20.4.
|
|
46
|
-
"@commitlint/config-conventional": "~20.4.
|
|
45
|
+
"@commitlint/cli": "~20.4.3",
|
|
46
|
+
"@commitlint/config-conventional": "~20.4.3",
|
|
47
47
|
"@eslint/js": "~9.39.2",
|
|
48
48
|
"@types/chai": "~5.2.3",
|
|
49
49
|
"@types/mocha": "~10.0.10",
|
|
50
|
-
"c8": "~
|
|
50
|
+
"c8": "~11.0.0",
|
|
51
51
|
"chai": "~6.2.2",
|
|
52
52
|
"esbuild": "~0.27.3",
|
|
53
53
|
"eslint": "~9.39.2",
|
|
54
54
|
"eslint-config-prettier": "~10.1.8",
|
|
55
55
|
"eslint-plugin-chai-expect": "~3.1.0",
|
|
56
56
|
"eslint-plugin-import": "~2.32.0",
|
|
57
|
-
"eslint-plugin-jsdoc": "~62.
|
|
57
|
+
"eslint-plugin-jsdoc": "~62.7.1",
|
|
58
58
|
"eslint-plugin-mocha": "~11.2.0",
|
|
59
|
-
"globals": "~17.
|
|
59
|
+
"globals": "~17.4.0",
|
|
60
60
|
"husky": "~9.1.7",
|
|
61
61
|
"mocha": "~11.7.5",
|
|
62
62
|
"prettier": "~3.8.1",
|
|
63
|
-
"rimraf": "~6.1.
|
|
63
|
+
"rimraf": "~6.1.3",
|
|
64
64
|
"typescript": "~5.9.3"
|
|
65
65
|
}
|
|
66
66
|
}
|
|
@@ -74,18 +74,18 @@ export class HttpStaticRouter extends DebuggableService {
|
|
|
74
74
|
options,
|
|
75
75
|
);
|
|
76
76
|
}
|
|
77
|
-
// options.
|
|
78
|
-
if (options.
|
|
79
|
-
if (typeof options.
|
|
77
|
+
// options.baseDir
|
|
78
|
+
if (options.baseDir !== undefined) {
|
|
79
|
+
if (typeof options.baseDir !== 'string') {
|
|
80
80
|
throw new InvalidArgumentError(
|
|
81
|
-
'Option "
|
|
82
|
-
options.
|
|
81
|
+
'Option "baseDir" must be a String, but %v was given.',
|
|
82
|
+
options.baseDir,
|
|
83
83
|
);
|
|
84
84
|
}
|
|
85
|
-
if (!path.isAbsolute(options.
|
|
85
|
+
if (!path.isAbsolute(options.baseDir)) {
|
|
86
86
|
throw new InvalidArgumentError(
|
|
87
|
-
'Option "
|
|
88
|
-
options.
|
|
87
|
+
'Option "baseDir" must be an absolute path, but %v was given.',
|
|
88
|
+
options.baseDir,
|
|
89
89
|
);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
@@ -108,12 +108,12 @@ export class HttpStaticRouter extends DebuggableService {
|
|
|
108
108
|
);
|
|
109
109
|
}
|
|
110
110
|
if (
|
|
111
|
-
this._options.
|
|
111
|
+
this._options.baseDir !== undefined &&
|
|
112
112
|
!path.isAbsolute(routeDef.resourcePath)
|
|
113
113
|
) {
|
|
114
114
|
routeDef = {...routeDef};
|
|
115
115
|
routeDef.resourcePath = path.join(
|
|
116
|
-
this._options.
|
|
116
|
+
this._options.baseDir,
|
|
117
117
|
routeDef.resourcePath,
|
|
118
118
|
);
|
|
119
119
|
}
|