routup 1.0.0 → 1.0.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 +2 -1
- package/dist/constants.d.ts +1 -1
- package/dist/index.cjs +27 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +29 -29
- package/dist/index.mjs.map +1 -1
- package/dist/route/module.d.ts +2 -2
- package/package.json +18 -18
package/README.md
CHANGED
|
@@ -66,7 +66,8 @@ router.listen(3000);
|
|
|
66
66
|
|
|
67
67
|
## Plugins
|
|
68
68
|
|
|
69
|
-
According to the fact that routup is a minimalistic framework,
|
|
69
|
+
According to the fact that routup is a minimalistic framework,
|
|
70
|
+
it depends on [plugins](https://github.com/routup/plugins) to cover some
|
|
70
71
|
typically http framework functions, which are not integrated in the main package.
|
|
71
72
|
|
|
72
73
|
| Name | Description |
|
package/dist/constants.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -235,16 +235,16 @@ function getConfigOption(key) {
|
|
|
235
235
|
return config.get(key);
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
exports.
|
|
239
|
-
(function(
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
})(exports.
|
|
238
|
+
exports.MethodName = void 0;
|
|
239
|
+
(function(MethodName) {
|
|
240
|
+
MethodName["GET"] = 'get';
|
|
241
|
+
MethodName["POST"] = 'post';
|
|
242
|
+
MethodName["PUT"] = 'put';
|
|
243
|
+
MethodName["PATCH"] = 'patch';
|
|
244
|
+
MethodName["DELETE"] = 'delete';
|
|
245
|
+
MethodName["OPTIONS"] = 'options';
|
|
246
|
+
MethodName["HEAD"] = 'head';
|
|
247
|
+
})(exports.MethodName || (exports.MethodName = {}));
|
|
248
248
|
exports.HeaderName = void 0;
|
|
249
249
|
(function(HeaderName) {
|
|
250
250
|
HeaderName["ACCEPT"] = 'accept';
|
|
@@ -993,7 +993,7 @@ function sendFile(res, filePath, fn) {
|
|
|
993
993
|
}
|
|
994
994
|
|
|
995
995
|
function sendFormat(res, input) {
|
|
996
|
-
const { default: formatDefault
|
|
996
|
+
const { default: formatDefault, ...formats } = input;
|
|
997
997
|
const contentTypes = Object.keys(formats);
|
|
998
998
|
const contentType = getRequestAcceptableContentType(res.req, contentTypes);
|
|
999
999
|
if (contentType) {
|
|
@@ -1156,16 +1156,16 @@ class Route {
|
|
|
1156
1156
|
}
|
|
1157
1157
|
matchMethod(method) {
|
|
1158
1158
|
let name = method.toLowerCase();
|
|
1159
|
-
if (name === exports.
|
|
1160
|
-
name = exports.
|
|
1159
|
+
if (name === exports.MethodName.HEAD && !smob.hasOwnProperty(this.layers, name)) {
|
|
1160
|
+
name = exports.MethodName.GET;
|
|
1161
1161
|
}
|
|
1162
1162
|
return Object.prototype.hasOwnProperty.call(this.layers, name);
|
|
1163
1163
|
}
|
|
1164
1164
|
// --------------------------------------------------
|
|
1165
1165
|
getMethods() {
|
|
1166
1166
|
const keys = Object.keys(this.layers);
|
|
1167
|
-
if (smob.hasOwnProperty(this.layers, exports.
|
|
1168
|
-
keys.push(exports.
|
|
1167
|
+
if (smob.hasOwnProperty(this.layers, exports.MethodName.GET) && !smob.hasOwnProperty(this.layers, exports.MethodName.HEAD)) {
|
|
1168
|
+
keys.push(exports.MethodName.HEAD);
|
|
1169
1169
|
}
|
|
1170
1170
|
return keys;
|
|
1171
1171
|
}
|
|
@@ -1176,8 +1176,8 @@ class Route {
|
|
|
1176
1176
|
return;
|
|
1177
1177
|
}
|
|
1178
1178
|
let name = req.method.toLowerCase();
|
|
1179
|
-
if (name === exports.
|
|
1180
|
-
name = exports.
|
|
1179
|
+
if (name === exports.MethodName.HEAD && !smob.hasOwnProperty(this.layers, name)) {
|
|
1180
|
+
name = exports.MethodName.GET;
|
|
1181
1181
|
}
|
|
1182
1182
|
const layers = this.layers[name];
|
|
1183
1183
|
/* istanbul ignore next */ if (typeof layers === 'undefined' || layers.length === 0 || typeof meta.path === 'undefined') {
|
|
@@ -1221,25 +1221,25 @@ class Route {
|
|
|
1221
1221
|
}
|
|
1222
1222
|
}
|
|
1223
1223
|
get(...handlers) {
|
|
1224
|
-
return this.register(exports.
|
|
1224
|
+
return this.register(exports.MethodName.GET, ...handlers);
|
|
1225
1225
|
}
|
|
1226
1226
|
post(...handlers) {
|
|
1227
|
-
return this.register(exports.
|
|
1227
|
+
return this.register(exports.MethodName.POST, ...handlers);
|
|
1228
1228
|
}
|
|
1229
1229
|
put(...handlers) {
|
|
1230
|
-
return this.register(exports.
|
|
1230
|
+
return this.register(exports.MethodName.PUT, ...handlers);
|
|
1231
1231
|
}
|
|
1232
1232
|
patch(...handlers) {
|
|
1233
|
-
return this.register(exports.
|
|
1233
|
+
return this.register(exports.MethodName.PATCH, ...handlers);
|
|
1234
1234
|
}
|
|
1235
1235
|
delete(...handlers) {
|
|
1236
|
-
return this.register(exports.
|
|
1236
|
+
return this.register(exports.MethodName.DELETE, ...handlers);
|
|
1237
1237
|
}
|
|
1238
1238
|
head(...handlers) {
|
|
1239
|
-
return this.register(exports.
|
|
1239
|
+
return this.register(exports.MethodName.HEAD, ...handlers);
|
|
1240
1240
|
}
|
|
1241
1241
|
options(...handlers) {
|
|
1242
|
-
return this.register(exports.
|
|
1242
|
+
return this.register(exports.MethodName.OPTIONS, ...handlers);
|
|
1243
1243
|
}
|
|
1244
1244
|
// --------------------------------------------------
|
|
1245
1245
|
isStrictPath() {
|
|
@@ -1324,7 +1324,7 @@ class Router {
|
|
|
1324
1324
|
res.end();
|
|
1325
1325
|
return;
|
|
1326
1326
|
}
|
|
1327
|
-
if (req.method && req.method.toLowerCase() === exports.
|
|
1327
|
+
if (req.method && req.method.toLowerCase() === exports.MethodName.OPTIONS) {
|
|
1328
1328
|
const options = allowedMethods.map((key)=>key.toUpperCase()).join(',');
|
|
1329
1329
|
res.setHeader(exports.HeaderName.ALLOW, options);
|
|
1330
1330
|
send(res, options);
|
|
@@ -1373,8 +1373,8 @@ class Router {
|
|
|
1373
1373
|
match = layer.matchPath(path);
|
|
1374
1374
|
if (req.method && !layer.matchMethod(req.method)) {
|
|
1375
1375
|
match = false;
|
|
1376
|
-
if (req.method.toLowerCase() === exports.
|
|
1377
|
-
allowedMethods = smob.
|
|
1376
|
+
if (req.method.toLowerCase() === exports.MethodName.OPTIONS) {
|
|
1377
|
+
allowedMethods = smob.distinctArray(smob.merge(allowedMethods, layer.getMethods()));
|
|
1378
1378
|
}
|
|
1379
1379
|
}
|
|
1380
1380
|
}
|