@e22m4u/js-http-static-router 0.1.0 → 0.1.1

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 CHANGED
@@ -30,25 +30,25 @@ import {HttpStaticRouter} from '@e22m4u/js-http-static-router';
30
30
 
31
31
  // создание экземпляра маршрутизатора
32
32
  const staticRouter = new HttpStaticRouter({
33
- // при использовании опции "rootDir", относительные пути
33
+ // при использовании опции "baseDir", относительные пути
34
34
  // в регистрируемых маршрутах будут разрешаться относительно
35
35
  // указанного адреса файловой системы
36
- rootDir: import.meta.dirname,
37
- // в данном случае "rootDir" указывает
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
- // доступным по адресу "/assets/{file_name}"
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
- // доступным по адресу "/home"
51
+ // для доступа по адресу "/home"
52
52
  staticRouter.defineRoute({
53
53
  remotePath: '/home',
54
54
  resourcePath: './static/index.html',
@@ -200,17 +200,17 @@ var _HttpStaticRouter = class _HttpStaticRouter extends import_js_service.Debugg
200
200
  options
201
201
  );
202
202
  }
203
- if (options.rootDir !== void 0) {
204
- if (typeof options.rootDir !== "string") {
203
+ if (options.baseDir !== void 0) {
204
+ if (typeof options.baseDir !== "string") {
205
205
  throw new import_js_format3.InvalidArgumentError(
206
- 'Option "rootDir" must be a String, but %v was given.',
207
- options.rootDir
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.rootDir)) {
210
+ if (!import_path2.default.isAbsolute(options.baseDir)) {
211
211
  throw new import_js_format3.InvalidArgumentError(
212
- 'Option "rootDir" must be an absolute path, but %v was given.',
213
- options.rootDir
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.rootDir !== void 0 && !import_path2.default.isAbsolute(routeDef.resourcePath)) {
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.rootDir,
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
- // при использовании опции "rootDir", относительные пути
6
+ // при использовании опции "baseDir", относительные пути
7
7
  // в регистрируемых маршрутах будут разрешаться относительно
8
8
  // указанного адреса файловой системы
9
- rootDir: import.meta.dirname,
9
+ baseDir: import.meta.dirname,
10
10
  });
11
11
 
12
12
  // экспозиция содержимого директории "/static"
13
- // доступным по адресу "/assets/{file_name}"
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
- // доступным по адресу "/home"
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.0",
3
+ "version": "0.1.1",
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.3.2",
40
+ "@e22m4u/js-format": "~0.4.0",
41
41
  "@e22m4u/js-service": "~0.5.1",
42
42
  "mime-types": "~3.0.2"
43
43
  },
44
44
  "devDependencies": {
45
- "@commitlint/cli": "~20.4.1",
46
- "@commitlint/config-conventional": "~20.4.1",
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": "~10.1.3",
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.5.4",
57
+ "eslint-plugin-jsdoc": "~62.7.1",
58
58
  "eslint-plugin-mocha": "~11.2.0",
59
- "globals": "~17.3.0",
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.2",
63
+ "rimraf": "~6.1.3",
64
64
  "typescript": "~5.9.3"
65
65
  }
66
66
  }
@@ -7,7 +7,7 @@ import {DebuggableService, ServiceContainer} from '@e22m4u/js-service';
7
7
  * Http static router options.
8
8
  */
9
9
  export type HttpStaticRouterOptions = {
10
- rootDir?: string;
10
+ baseDir?: string;
11
11
  };
12
12
 
13
13
  /**
@@ -74,18 +74,18 @@ export class HttpStaticRouter extends DebuggableService {
74
74
  options,
75
75
  );
76
76
  }
77
- // options.rootDir
78
- if (options.rootDir !== undefined) {
79
- if (typeof options.rootDir !== 'string') {
77
+ // options.baseDir
78
+ if (options.baseDir !== undefined) {
79
+ if (typeof options.baseDir !== 'string') {
80
80
  throw new InvalidArgumentError(
81
- 'Option "rootDir" must be a String, but %v was given.',
82
- options.rootDir,
81
+ 'Option "baseDir" must be a String, but %v was given.',
82
+ options.baseDir,
83
83
  );
84
84
  }
85
- if (!path.isAbsolute(options.rootDir)) {
85
+ if (!path.isAbsolute(options.baseDir)) {
86
86
  throw new InvalidArgumentError(
87
- 'Option "rootDir" must be an absolute path, but %v was given.',
88
- options.rootDir,
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.rootDir !== undefined &&
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.rootDir,
116
+ this._options.baseDir,
117
117
  routeDef.resourcePath,
118
118
  );
119
119
  }