@feathersjs/express 5.0.0-pre.22 → 5.0.0-pre.25
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/CHANGELOG.md +35 -0
- package/lib/authentication.js +1 -1
- package/lib/authentication.js.map +1 -1
- package/lib/handlers.js +5 -3
- package/lib/handlers.js.map +1 -1
- package/lib/index.d.ts +6 -6
- package/lib/index.js +29 -17
- package/lib/index.js.map +1 -1
- package/lib/rest.js +5 -1
- package/lib/rest.js.map +1 -1
- package/package.json +12 -12
- package/src/authentication.ts +38 -33
- package/src/declarations.ts +37 -32
- package/src/handlers.ts +53 -51
- package/src/index.ts +86 -64
- package/src/rest.ts +70 -64
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,41 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [5.0.0-pre.25](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.24...v5.0.0-pre.25) (2022-06-22)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @feathersjs/express
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [5.0.0-pre.24](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.23...v5.0.0-pre.24) (2022-06-21)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **authentication:** Add safe dispatch data for authentication requests ([#2662](https://github.com/feathersjs/feathers/issues/2662)) ([d8104a1](https://github.com/feathersjs/feathers/commit/d8104a19ee9181e6a5ea81014af29ff9a3c28a8a))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* **cli:** Add support for JavaScript to the new CLI ([#2668](https://github.com/feathersjs/feathers/issues/2668)) ([ebac587](https://github.com/feathersjs/feathers/commit/ebac587f7d00dc7607c3f546352d79f79b89a5d4))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# [5.0.0-pre.23](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.22...v5.0.0-pre.23) (2022-06-06)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Bug Fixes
|
|
34
|
+
|
|
35
|
+
* **express:** Ensure Express options can be set before configuring REST transport ([#2655](https://github.com/feathersjs/feathers/issues/2655)) ([c9b8f74](https://github.com/feathersjs/feathers/commit/c9b8f74a0196acb99be44ac5e0fff3f1128288cd))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
6
41
|
# [5.0.0-pre.22](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.21...v5.0.0-pre.22) (2022-05-24)
|
|
7
42
|
|
|
8
43
|
**Note:** Version bump only for package @feathersjs/express
|
package/lib/authentication.js
CHANGED
|
@@ -5,7 +5,7 @@ const commons_1 = require("@feathersjs/commons");
|
|
|
5
5
|
const authentication_1 = require("@feathersjs/authentication");
|
|
6
6
|
const debug = (0, commons_1.createDebug)('@feathersjs/express/authentication');
|
|
7
7
|
const toHandler = (func) => {
|
|
8
|
-
return (req, res, next) => func(req, res, next).catch(error => next(error));
|
|
8
|
+
return (req, res, next) => func(req, res, next).catch((error) => next(error));
|
|
9
9
|
};
|
|
10
10
|
function parseAuthentication(settings = {}) {
|
|
11
11
|
return toHandler(async (req, res, next) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.js","sourceRoot":"","sources":["../src/authentication.ts"],"names":[],"mappings":";;;AAEA,
|
|
1
|
+
{"version":3,"file":"authentication.js","sourceRoot":"","sources":["../src/authentication.ts"],"names":[],"mappings":";;;AAEA,iDAAiD;AACjD,+DAA6E;AAI7E,MAAM,KAAK,GAAG,IAAA,qBAAW,EAAC,oCAAoC,CAAC,CAAA;AAE/D,MAAM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C1B,QAAyC,EACzC,GAAG,UAAoB;IAEvB,MAAM,IAAI,GAAG,IAAA,6BAAgB,EAAC,QAAQ,EAAE,GAAG,UAAU,CAAC,CAAA;IAEtD,OAAO,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;QACzC,MAAM,GAAG,GAAG,GAAG,CAAC,GAAyB,CAAA;QACzC,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAA;QAC3B,MAAM,OAAO,GAAG,EAAE,GAAG,EAAE,MAAM,EAAwB,CAAA;QAErD,MAAM,IAAI,CAAC,OAAO,CAAC,CAAA;QAEnB,GAAG,CAAC,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAA;QAE7B,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAC,CAAA;AACJ,CAAC;AAjBD,oCAiBC"}
|
package/lib/handlers.js
CHANGED
|
@@ -45,9 +45,11 @@ function errorHandler(_options = {}) {
|
|
|
45
45
|
}
|
|
46
46
|
if (error.type !== 'FeathersError') {
|
|
47
47
|
const oldError = error;
|
|
48
|
-
error = oldError.errors
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
error = oldError.errors
|
|
49
|
+
? new errors_1.GeneralError(oldError.message, {
|
|
50
|
+
errors: oldError.errors
|
|
51
|
+
})
|
|
52
|
+
: new errors_1.GeneralError(oldError.message);
|
|
51
53
|
if (oldError.stack) {
|
|
52
54
|
error.stack = oldError.stack;
|
|
53
55
|
}
|
package/lib/handlers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../src/handlers.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../src/handlers.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AACvB,+CAA2D;AAG3D,MAAM,QAAQ,GAAG;IACf,MAAM,EAAE,cAAI,CAAC,OAAO,CAAC,SAAS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KAAK,CAAC,IAAI,CAAC,CAAA;QAEtB,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,CAAA;QACrD,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAA;QAExC,iCAAiC;QACjC,IAAI,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE;YACxE,SAAS,CAAC,kBAAkB,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;SACrD;aAAM,IAAI,OAAO,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;YACjG,SAAS,CAAC,WAAW,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;SAC9C;aAAM;YACL,0CAA0C;YAC1C,SAAS,CAAC,kBAAkB,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;SACrD;IACH,CAAC,CAAA;AACH,CAAC;AAzGD,oCAyGC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Express } from 'express';
|
|
2
2
|
import { Application as FeathersApplication } from '@feathersjs/feathers';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
3
|
+
import { rest, RestOptions, formatter } from './rest';
|
|
4
|
+
import { errorHandler, notFound, ErrorHandlerOptions } from './handlers';
|
|
5
|
+
import { Application, ExpressOverrides } from './declarations';
|
|
6
|
+
import { AuthenticationSettings, authenticate, parseAuthentication } from './authentication';
|
|
7
|
+
import { default as original, static as serveStatic, json, raw, text, urlencoded, query } from 'express';
|
|
8
|
+
export { original, serveStatic, serveStatic as static, json, raw, text, urlencoded, query, rest, RestOptions, formatter, errorHandler, notFound, Application, ErrorHandlerOptions, ExpressOverrides, AuthenticationSettings, parseAuthentication, authenticate };
|
|
9
9
|
export default function feathersExpress<S = any, C = any>(feathersApp?: FeathersApplication<S, C>, expressApp?: Express): Application<S, C>;
|
package/lib/index.js
CHANGED
|
@@ -10,31 +10,45 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
-
var
|
|
14
|
-
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
15
24
|
};
|
|
16
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
27
|
};
|
|
19
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.query = exports.urlencoded = exports.text = exports.raw = exports.json = exports.
|
|
29
|
+
exports.authenticate = exports.parseAuthentication = exports.notFound = exports.errorHandler = exports.formatter = exports.rest = exports.query = exports.urlencoded = exports.text = exports.raw = exports.json = exports.static = exports.serveStatic = exports.original = void 0;
|
|
21
30
|
const express_1 = __importDefault(require("express"));
|
|
22
31
|
const feathers_1 = require("@feathersjs/feathers");
|
|
23
32
|
const transport_commons_1 = require("@feathersjs/transport-commons");
|
|
24
33
|
const commons_1 = require("@feathersjs/commons");
|
|
25
|
-
|
|
26
|
-
Object.defineProperty(exports, "
|
|
27
|
-
Object.defineProperty(exports, "
|
|
34
|
+
const rest_1 = require("./rest");
|
|
35
|
+
Object.defineProperty(exports, "rest", { enumerable: true, get: function () { return rest_1.rest; } });
|
|
36
|
+
Object.defineProperty(exports, "formatter", { enumerable: true, get: function () { return rest_1.formatter; } });
|
|
37
|
+
const handlers_1 = require("./handlers");
|
|
38
|
+
Object.defineProperty(exports, "errorHandler", { enumerable: true, get: function () { return handlers_1.errorHandler; } });
|
|
39
|
+
Object.defineProperty(exports, "notFound", { enumerable: true, get: function () { return handlers_1.notFound; } });
|
|
40
|
+
const authentication_1 = require("./authentication");
|
|
41
|
+
Object.defineProperty(exports, "authenticate", { enumerable: true, get: function () { return authentication_1.authenticate; } });
|
|
42
|
+
Object.defineProperty(exports, "parseAuthentication", { enumerable: true, get: function () { return authentication_1.parseAuthentication; } });
|
|
43
|
+
const express_2 = __importStar(require("express"));
|
|
44
|
+
Object.defineProperty(exports, "original", { enumerable: true, get: function () { return express_2.default; } });
|
|
28
45
|
Object.defineProperty(exports, "serveStatic", { enumerable: true, get: function () { return express_2.static; } });
|
|
46
|
+
Object.defineProperty(exports, "static", { enumerable: true, get: function () { return express_2.static; } });
|
|
29
47
|
Object.defineProperty(exports, "json", { enumerable: true, get: function () { return express_2.json; } });
|
|
30
48
|
Object.defineProperty(exports, "raw", { enumerable: true, get: function () { return express_2.raw; } });
|
|
31
49
|
Object.defineProperty(exports, "text", { enumerable: true, get: function () { return express_2.text; } });
|
|
32
50
|
Object.defineProperty(exports, "urlencoded", { enumerable: true, get: function () { return express_2.urlencoded; } });
|
|
33
51
|
Object.defineProperty(exports, "query", { enumerable: true, get: function () { return express_2.query; } });
|
|
34
|
-
__exportStar(require("./authentication"), exports);
|
|
35
|
-
__exportStar(require("./declarations"), exports);
|
|
36
|
-
__exportStar(require("./handlers"), exports);
|
|
37
|
-
__exportStar(require("./rest"), exports);
|
|
38
52
|
const debug = (0, commons_1.createDebug)('@feathersjs/express');
|
|
39
53
|
function feathersExpress(feathersApp, expressApp = (0, express_1.default)()) {
|
|
40
54
|
if (!feathersApp) {
|
|
@@ -68,7 +82,7 @@ function feathersExpress(feathersApp, expressApp = (0, express_1.default)()) {
|
|
|
68
82
|
before: [],
|
|
69
83
|
after: []
|
|
70
84
|
});
|
|
71
|
-
const hasMethod = (methods) => methods.some(name =>
|
|
85
|
+
const hasMethod = (methods) => methods.some((name) => service && typeof service[name] === 'function');
|
|
72
86
|
// Check for service (any object with at least one service method)
|
|
73
87
|
if (hasMethod(['handle', 'set']) || !hasMethod(feathers_1.defaultServiceMethods)) {
|
|
74
88
|
debug('Passing app.use call to Express app');
|
|
@@ -90,7 +104,9 @@ function feathersExpress(feathersApp, expressApp = (0, express_1.default)()) {
|
|
|
90
104
|
return server;
|
|
91
105
|
},
|
|
92
106
|
async teardown(server) {
|
|
93
|
-
return feathersTeardown
|
|
107
|
+
return feathersTeardown
|
|
108
|
+
.call(this, server)
|
|
109
|
+
.then(() => new Promise((resolve, reject) => this.server.close((e) => (e ? reject(e) : resolve(this)))));
|
|
94
110
|
}
|
|
95
111
|
});
|
|
96
112
|
const appDescriptors = {
|
|
@@ -103,7 +119,7 @@ function feathersExpress(feathersApp, expressApp = (0, express_1.default)()) {
|
|
|
103
119
|
};
|
|
104
120
|
// Copy all non-existing properties (including non-enumerables)
|
|
105
121
|
// that don't already exist on the Express app
|
|
106
|
-
Object.keys(newDescriptors).forEach(prop => {
|
|
122
|
+
Object.keys(newDescriptors).forEach((prop) => {
|
|
107
123
|
const appProp = appDescriptors[prop];
|
|
108
124
|
const newProp = newDescriptors[prop];
|
|
109
125
|
if (appProp === undefined && newProp !== undefined) {
|
|
@@ -111,10 +127,6 @@ function feathersExpress(feathersApp, expressApp = (0, express_1.default)()) {
|
|
|
111
127
|
}
|
|
112
128
|
});
|
|
113
129
|
app.configure((0, transport_commons_1.routing)());
|
|
114
|
-
app.use((req, _res, next) => {
|
|
115
|
-
req.feathers = { ...req.feathers, provider: 'rest' };
|
|
116
|
-
return next();
|
|
117
|
-
});
|
|
118
130
|
return app;
|
|
119
131
|
}
|
|
120
132
|
exports.default = feathersExpress;
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAA0C;AAC1C,mDAAgG;AAChG,qEAAuD;AACvD,iDAAiD;AAEjD,iCAAqD;AAenD,qFAfO,WAAI,OAeP;AAEJ,0FAjB0B,gBAAS,OAiB1B;AAhBX,yCAAwE;AAiBtE,6FAjBO,uBAAY,OAiBP;AACZ,yFAlBqB,mBAAQ,OAkBrB;AAhBV,qDAA4F;AAsB1F,6FAtB+B,6BAAY,OAsB/B;AADZ,oGArB6C,oCAAmB,OAqB7C;AApBrB,mDAAwG;AAGtG,yFAHkB,iBAAQ,OAGlB;AACR,4FAJsC,gBAAW,OAItC;AACI,uFALuB,gBAAW,OAK5B;AACrB,qFANmD,cAAI,OAMnD;AACJ,oFAPyD,aAAG,OAOzD;AACH,qFAR8D,cAAI,OAQ9D;AACJ,2FAToE,oBAAU,OASpE;AACV,sFAVgF,eAAK,OAUhF;AAcP,MAAM,KAAK,GAAG,IAAA,qBAAW,EAAC,qBAAqB,CAAC,CAAA;AAEhD,SAAwB,eAAe,CACrC,WAAuC,EACvC,aAAsB,IAAA,iBAAO,GAAE;IAE/B,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO,UAAiB,CAAA;KACzB;IAED,IAAI,OAAO,WAAW,CAAC,KAAK,KAAK,UAAU,EAAE;QAC3C,MAAM,IAAI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cAAc,CAAC,GAAG,CAAC,CAAC;QAC/D,GAAG,MAAM,CAAC,yBAAyB,CAAC,GAAG,CAAC;KACzC,CAAA;IACD,MAAM,cAAc,GAAG;QACrB,GAAG,MAAM,CAAC,yBAAyB,CAAC,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;QACvE,GAAG,MAAM,CAAC,yBAAyB,CAAC,WAAW,CAAC;KACjD,CAAA;IAED,+DAA+D;IAC/D,8CAA8C;IAC9C,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC3C,MAAM,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,CAAA;QACpC,MAAM,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,CAAA;QAEpC,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,SAAS,EAAE;YAClD,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;SACjD;IACH,CAAC,CAAC,CAAA;IAEF,GAAG,CAAC,SAAS,CAAC,IAAA,2BAAO,GAAS,CAAC,CAAA;IAE/B,OAAO,GAAG,CAAA;AACZ,CAAC;AArGD,kCAqGC;AAED,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACjC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;CAChE"}
|
package/lib/rest.js
CHANGED
|
@@ -9,7 +9,7 @@ const feathers_1 = require("@feathersjs/feathers");
|
|
|
9
9
|
const authentication_1 = require("./authentication");
|
|
10
10
|
const debug = (0, commons_1.createDebug)('@feathersjs/express/rest');
|
|
11
11
|
const toHandler = (func) => {
|
|
12
|
-
return (req, res, next) => func(req, res, next).catch(error => next(error));
|
|
12
|
+
return (req, res, next) => func(req, res, next).catch((error) => next(error));
|
|
13
13
|
};
|
|
14
14
|
const serviceMiddleware = () => {
|
|
15
15
|
return toHandler(async (req, res, next) => {
|
|
@@ -70,6 +70,10 @@ const rest = (options) => {
|
|
|
70
70
|
if (typeof app.route !== 'function') {
|
|
71
71
|
throw new Error('@feathersjs/express/rest needs an Express compatible app.');
|
|
72
72
|
}
|
|
73
|
+
app.use((req, _res, next) => {
|
|
74
|
+
req.feathers = { ...req.feathers, provider: 'rest' };
|
|
75
|
+
return next();
|
|
76
|
+
});
|
|
73
77
|
app.use((0, authentication_1.parseAuthentication)(authenticationOptions));
|
|
74
78
|
app.use(servicesMiddleware());
|
|
75
79
|
app.mixins.push((_service, _path, options) => {
|
package/lib/rest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../src/rest.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../src/rest.ts"],"names":[],"mappings":";;;AAAA,qCAAmE;AACnE,+CAAqD;AACrD,iDAAiD;AACjD,qEAAoD;AACpD,mDAA8F;AAE9F,qDAA8E;AAG9E,MAAM,KAAK,GAAG,IAAA,qBAAW,EAAC,0BAA0B,CAAC,CAAA;AAErD,MAAM,SAAS,GAAG,CAChB,IAAsE,EACtD,EAAE;IAClB,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;AAC/E,CAAC,CAAA;AAED,MAAM,iBAAiB,GAAG,GAAmB,EAAE;IAC7C,OAAO,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACxC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,GAAG,CAAA;QACpE,MAAM,c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C,CAAA;YACtF,MAAM,UAAU,GAAG,IAAA,gBAAM,GAAE,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;YAE5C,OAAO,CAAC,OAAO,KAAf,OAAO,CAAC,OAAO,GAAK,EAAE,EAAA;YACtB,OAAO,CAAC,OAAO,CAAC,QAAQ,GAAG,UAAU,CAAA;QACvC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;AACH,CAAC,CAAA;AA5BY,QAAA,IAAI,QA4BhB"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@feathersjs/express",
|
|
3
3
|
"description": "Feathers Express framework bindings and REST provider",
|
|
4
|
-
"version": "5.0.0-pre.
|
|
4
|
+
"version": "5.0.0-pre.25",
|
|
5
5
|
"homepage": "https://feathersjs.com",
|
|
6
6
|
"main": "lib/",
|
|
7
7
|
"types": "lib/",
|
|
@@ -51,27 +51,27 @@
|
|
|
51
51
|
"access": "public"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@feathersjs/authentication": "^5.0.0-pre.
|
|
55
|
-
"@feathersjs/commons": "^5.0.0-pre.
|
|
56
|
-
"@feathersjs/errors": "^5.0.0-pre.
|
|
57
|
-
"@feathersjs/feathers": "^5.0.0-pre.
|
|
58
|
-
"@feathersjs/transport-commons": "^5.0.0-pre.
|
|
54
|
+
"@feathersjs/authentication": "^5.0.0-pre.25",
|
|
55
|
+
"@feathersjs/commons": "^5.0.0-pre.25",
|
|
56
|
+
"@feathersjs/errors": "^5.0.0-pre.25",
|
|
57
|
+
"@feathersjs/feathers": "^5.0.0-pre.25",
|
|
58
|
+
"@feathersjs/transport-commons": "^5.0.0-pre.25",
|
|
59
59
|
"@types/express": "^4.17.13",
|
|
60
60
|
"@types/express-serve-static-core": "^4.17.28",
|
|
61
61
|
"express": "^4.18.1"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@feathersjs/authentication-local": "^5.0.0-pre.
|
|
65
|
-
"@feathersjs/tests": "^5.0.0-pre.
|
|
64
|
+
"@feathersjs/authentication-local": "^5.0.0-pre.25",
|
|
65
|
+
"@feathersjs/tests": "^5.0.0-pre.25",
|
|
66
66
|
"@types/lodash": "^4.14.182",
|
|
67
67
|
"@types/mocha": "^9.1.1",
|
|
68
|
-
"@types/node": "^17.0.
|
|
68
|
+
"@types/node": "^17.0.40",
|
|
69
69
|
"axios": "^0.27.2",
|
|
70
70
|
"lodash": "^4.17.21",
|
|
71
71
|
"mocha": "^10.0.0",
|
|
72
72
|
"shx": "^0.3.4",
|
|
73
|
-
"ts-node": "^10.
|
|
74
|
-
"typescript": "^4.
|
|
73
|
+
"ts-node": "^10.8.1",
|
|
74
|
+
"typescript": "^4.7.3"
|
|
75
75
|
},
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "c0ab3b603920dff6e9c912b2767cf168094d45c8"
|
|
77
77
|
}
|
package/src/authentication.ts
CHANGED
|
@@ -1,61 +1,66 @@
|
|
|
1
|
-
import { RequestHandler, Request, Response } from 'express'
|
|
2
|
-
import { HookContext } from '@feathersjs/feathers'
|
|
3
|
-
import { createDebug } from '@feathersjs/commons'
|
|
4
|
-
import { authenticate as AuthenticateHook } from '@feathersjs/authentication'
|
|
1
|
+
import { RequestHandler, Request, Response } from 'express'
|
|
2
|
+
import { HookContext } from '@feathersjs/feathers'
|
|
3
|
+
import { createDebug } from '@feathersjs/commons'
|
|
4
|
+
import { authenticate as AuthenticateHook } from '@feathersjs/authentication'
|
|
5
5
|
|
|
6
|
-
import { Application } from './declarations'
|
|
6
|
+
import { Application } from './declarations'
|
|
7
7
|
|
|
8
|
-
const debug = createDebug('@feathersjs/express/authentication')
|
|
8
|
+
const debug = createDebug('@feathersjs/express/authentication')
|
|
9
9
|
|
|
10
|
-
const toHandler = (
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const toHandler = (
|
|
11
|
+
func: (req: Request, res: Response, next: () => void) => Promise<void>
|
|
12
|
+
): RequestHandler => {
|
|
13
|
+
return (req, res, next) => func(req, res, next).catch((error) => next(error))
|
|
14
|
+
}
|
|
13
15
|
|
|
14
16
|
export type AuthenticationSettings = {
|
|
15
|
-
service?: string
|
|
16
|
-
strategies?: string[]
|
|
17
|
-
}
|
|
17
|
+
service?: string
|
|
18
|
+
strategies?: string[]
|
|
19
|
+
}
|
|
18
20
|
|
|
19
|
-
export function parseAuthentication
|
|
21
|
+
export function parseAuthentication(settings: AuthenticationSettings = {}): RequestHandler {
|
|
20
22
|
return toHandler(async (req, res, next) => {
|
|
21
|
-
const app = req.app as any as Application
|
|
22
|
-
const service = app.defaultAuthentication?.(settings.service)
|
|
23
|
+
const app = req.app as any as Application
|
|
24
|
+
const service = app.defaultAuthentication?.(settings.service)
|
|
23
25
|
|
|
24
26
|
if (!service) {
|
|
25
|
-
return next()
|
|
27
|
+
return next()
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
const config = service.configuration
|
|
29
|
-
const authStrategies = settings.strategies || config.parseStrategies || config.authStrategies || []
|
|
30
|
+
const config = service.configuration
|
|
31
|
+
const authStrategies = settings.strategies || config.parseStrategies || config.authStrategies || []
|
|
30
32
|
|
|
31
33
|
if (authStrategies.length === 0) {
|
|
32
|
-
debug('No `authStrategies` or `parseStrategies` found in authentication configuration')
|
|
33
|
-
return next()
|
|
34
|
+
debug('No `authStrategies` or `parseStrategies` found in authentication configuration')
|
|
35
|
+
return next()
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
const authentication = await service.parse(req, res, ...authStrategies)
|
|
37
39
|
|
|
38
40
|
if (authentication) {
|
|
39
|
-
debug('Parsed authentication from HTTP header', authentication)
|
|
40
|
-
req.feathers = { ...req.feathers, authentication }
|
|
41
|
+
debug('Parsed authentication from HTTP header', authentication)
|
|
42
|
+
req.feathers = { ...req.feathers, authentication }
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
return next()
|
|
44
|
-
})
|
|
45
|
+
return next()
|
|
46
|
+
})
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
export function authenticate
|
|
48
|
-
|
|
49
|
+
export function authenticate(
|
|
50
|
+
settings: string | AuthenticationSettings,
|
|
51
|
+
...strategies: string[]
|
|
52
|
+
): RequestHandler {
|
|
53
|
+
const hook = AuthenticateHook(settings, ...strategies)
|
|
49
54
|
|
|
50
55
|
return toHandler(async (req, _res, next) => {
|
|
51
|
-
const app = req.app as any as Application
|
|
52
|
-
const params = req.feathers
|
|
53
|
-
const context = { app, params } as any as HookContext
|
|
56
|
+
const app = req.app as any as Application
|
|
57
|
+
const params = req.feathers
|
|
58
|
+
const context = { app, params } as any as HookContext
|
|
54
59
|
|
|
55
|
-
await hook(context)
|
|
60
|
+
await hook(context)
|
|
56
61
|
|
|
57
|
-
req.feathers = context.params
|
|
62
|
+
req.feathers = context.params
|
|
58
63
|
|
|
59
|
-
return next()
|
|
60
|
-
})
|
|
64
|
+
return next()
|
|
65
|
+
})
|
|
61
66
|
}
|
package/src/declarations.ts
CHANGED
|
@@ -1,63 +1,68 @@
|
|
|
1
|
-
import http from 'http'
|
|
2
|
-
import express, { Express } from 'express'
|
|
1
|
+
import http from 'http'
|
|
2
|
+
import express, { Express } from 'express'
|
|
3
3
|
import {
|
|
4
|
-
Application as FeathersApplication,
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
Application as FeathersApplication,
|
|
5
|
+
Params as FeathersParams,
|
|
6
|
+
HookContext,
|
|
7
|
+
ServiceMethods,
|
|
8
|
+
ServiceInterface,
|
|
9
|
+
RouteLookup
|
|
10
|
+
} from '@feathersjs/feathers'
|
|
7
11
|
|
|
8
12
|
interface ExpressUseHandler<T, Services> {
|
|
9
|
-
<L extends keyof Services & string>
|
|
13
|
+
<L extends keyof Services & string>(
|
|
10
14
|
path: L,
|
|
11
15
|
...middlewareOrService: (
|
|
12
|
-
Express
|
|
13
|
-
|
|
16
|
+
| Express
|
|
17
|
+
| express.RequestHandler
|
|
18
|
+
| express.RequestHandler[]
|
|
19
|
+
| (keyof any extends keyof Services ? ServiceInterface : Services[L])
|
|
14
20
|
)[]
|
|
15
|
-
): T
|
|
16
|
-
(path: string|RegExp, ...expressHandlers: express.RequestHandler[]): T
|
|
17
|
-
(...expressHandlers: express.RequestHandler[]): T
|
|
18
|
-
(handler: Express|express.ErrorRequestHandler): T
|
|
21
|
+
): T
|
|
22
|
+
(path: string | RegExp, ...expressHandlers: express.RequestHandler[]): T
|
|
23
|
+
(...expressHandlers: express.RequestHandler[]): T
|
|
24
|
+
(handler: Express | express.ErrorRequestHandler): T
|
|
19
25
|
}
|
|
20
26
|
|
|
21
27
|
export interface ExpressOverrides<Services> {
|
|
22
|
-
listen(port: number, hostname: string, backlog: number, callback?: () => void): Promise<http.Server
|
|
23
|
-
listen(port: number, hostname: string, callback?: () => void): Promise<http.Server
|
|
24
|
-
listen(port: number|string|any, callback?: () => void): Promise<http.Server
|
|
25
|
-
listen(callback?: () => void): Promise<http.Server
|
|
26
|
-
use: ExpressUseHandler<this, Services
|
|
27
|
-
server: http.Server
|
|
28
|
+
listen(port: number, hostname: string, backlog: number, callback?: () => void): Promise<http.Server>
|
|
29
|
+
listen(port: number, hostname: string, callback?: () => void): Promise<http.Server>
|
|
30
|
+
listen(port: number | string | any, callback?: () => void): Promise<http.Server>
|
|
31
|
+
listen(callback?: () => void): Promise<http.Server>
|
|
32
|
+
use: ExpressUseHandler<this, Services>
|
|
33
|
+
server: http.Server
|
|
28
34
|
}
|
|
29
35
|
|
|
30
|
-
export type Application<Services = any, Settings = any> =
|
|
31
|
-
Omit<Express, 'listen'|'use'|'get'|'set'> &
|
|
36
|
+
export type Application<Services = any, Settings = any> = Omit<Express, 'listen' | 'use' | 'get' | 'set'> &
|
|
32
37
|
FeathersApplication<Services, Settings> &
|
|
33
|
-
ExpressOverrides<Services
|
|
38
|
+
ExpressOverrides<Services>
|
|
34
39
|
|
|
35
40
|
declare module '@feathersjs/feathers/lib/declarations' {
|
|
36
41
|
interface ServiceOptions {
|
|
37
42
|
express?: {
|
|
38
|
-
before?: express.RequestHandler[]
|
|
39
|
-
after?: express.RequestHandler[]
|
|
40
|
-
composed?: express.RequestHandler
|
|
41
|
-
}
|
|
43
|
+
before?: express.RequestHandler[]
|
|
44
|
+
after?: express.RequestHandler[]
|
|
45
|
+
composed?: express.RequestHandler
|
|
46
|
+
}
|
|
42
47
|
}
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
declare module 'express-serve-static-core' {
|
|
46
51
|
interface Request {
|
|
47
|
-
feathers?: Partial<FeathersParams> & { [key: string]: any }
|
|
48
|
-
lookup?: RouteLookup
|
|
52
|
+
feathers?: Partial<FeathersParams> & { [key: string]: any }
|
|
53
|
+
lookup?: RouteLookup
|
|
49
54
|
}
|
|
50
55
|
|
|
51
56
|
interface Response {
|
|
52
|
-
data?: any
|
|
53
|
-
hook?: HookContext
|
|
57
|
+
data?: any
|
|
58
|
+
hook?: HookContext
|
|
54
59
|
}
|
|
55
60
|
|
|
56
61
|
interface IRouterMatcher<T> {
|
|
57
62
|
// eslint-disable-next-line
|
|
58
63
|
<P extends Params = ParamsDictionary, ResBody = any, ReqBody = any>(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
): T
|
|
64
|
+
path: PathParams,
|
|
65
|
+
...handlers: (RequestHandler<P, ResBody, ReqBody> | Partial<ServiceMethods> | Application)[]
|
|
66
|
+
): T
|
|
62
67
|
}
|
|
63
68
|
}
|
package/src/handlers.ts
CHANGED
|
@@ -1,130 +1,132 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import { NotFound, GeneralError } from '@feathersjs/errors'
|
|
3
|
-
import { Request, Response, NextFunction, ErrorRequestHandler, RequestHandler } from 'express'
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import { NotFound, GeneralError } from '@feathersjs/errors'
|
|
3
|
+
import { Request, Response, NextFunction, ErrorRequestHandler, RequestHandler } from 'express'
|
|
4
4
|
|
|
5
5
|
const defaults = {
|
|
6
6
|
public: path.resolve(__dirname, '..', 'public'),
|
|
7
7
|
logger: console
|
|
8
|
-
}
|
|
9
|
-
const defaultHtmlError = path.resolve(defaults.public, 'default.html')
|
|
8
|
+
}
|
|
9
|
+
const defaultHtmlError = path.resolve(defaults.public, 'default.html')
|
|
10
10
|
|
|
11
|
-
export function notFound
|
|
11
|
+
export function notFound({ verbose = false } = {}): RequestHandler {
|
|
12
12
|
return function (req: Request, _res: Response, next: NextFunction) {
|
|
13
|
-
const url = `${req.url}
|
|
14
|
-
const message = `Page not found${verbose ? ': ' + url : ''}
|
|
13
|
+
const url = `${req.url}`
|
|
14
|
+
const message = `Page not found${verbose ? ': ' + url : ''}`
|
|
15
15
|
|
|
16
|
-
next(new NotFound(message, { url }))
|
|
17
|
-
}
|
|
16
|
+
next(new NotFound(message, { url }))
|
|
17
|
+
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export type ErrorHandlerOptions = {
|
|
21
|
-
public?: string
|
|
22
|
-
logger?: boolean|{ error?: (msg: any) => void
|
|
23
|
-
html?: any
|
|
24
|
-
json?: any
|
|
25
|
-
}
|
|
21
|
+
public?: string
|
|
22
|
+
logger?: boolean | { error?: (msg: any) => void; info?: (msg: any) => void }
|
|
23
|
+
html?: any
|
|
24
|
+
json?: any
|
|
25
|
+
}
|
|
26
26
|
|
|
27
|
-
export function errorHandler
|
|
28
|
-
const options = Object.assign({}, defaults, _options)
|
|
27
|
+
export function errorHandler(_options: ErrorHandlerOptions = {}): ErrorRequestHandler {
|
|
28
|
+
const options = Object.assign({}, defaults, _options)
|
|
29
29
|
|
|
30
30
|
if (typeof options.html === 'undefined') {
|
|
31
31
|
options.html = {
|
|
32
32
|
401: path.resolve(options.public, '401.html'),
|
|
33
33
|
404: path.resolve(options.public, '404.html'),
|
|
34
34
|
default: defaultHtmlError
|
|
35
|
-
}
|
|
35
|
+
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
if (typeof options.json === 'undefined') {
|
|
39
|
-
options.json = {}
|
|
39
|
+
options.json = {}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
return function (error: any, req: Request, res: Response, next: NextFunction) {
|
|
43
43
|
// Set the error code for HTTP processing semantics
|
|
44
|
-
error.code = !isNaN(parseInt(error.code, 10)) ? parseInt(error.code, 10) : 500
|
|
44
|
+
error.code = !isNaN(parseInt(error.code, 10)) ? parseInt(error.code, 10) : 500
|
|
45
45
|
|
|
46
46
|
// Log the error if it didn't come from a service method call
|
|
47
47
|
if (options.logger && typeof options.logger.error === 'function' && !res.hook) {
|
|
48
48
|
if (error.code >= 500) {
|
|
49
|
-
options.logger.error(error)
|
|
49
|
+
options.logger.error(error)
|
|
50
50
|
} else {
|
|
51
|
-
options.logger.info(error)
|
|
51
|
+
options.logger.info(error)
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
if (error.type !== 'FeathersError') {
|
|
56
|
-
const oldError = error
|
|
56
|
+
const oldError = error
|
|
57
57
|
|
|
58
|
-
error = oldError.errors
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
error = oldError.errors
|
|
59
|
+
? new GeneralError(oldError.message, {
|
|
60
|
+
errors: oldError.errors
|
|
61
|
+
})
|
|
62
|
+
: new GeneralError(oldError.message)
|
|
61
63
|
|
|
62
64
|
if (oldError.stack) {
|
|
63
|
-
error.stack = oldError.stack
|
|
65
|
+
error.stack = oldError.stack
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
const formatter: { [key: string]: any } = {}
|
|
69
|
+
const formatter: { [key: string]: any } = {}
|
|
68
70
|
|
|
69
71
|
// If the developer passed a custom function for ALL html errors
|
|
70
72
|
if (typeof options.html === 'function') {
|
|
71
|
-
formatter['text/html'] = options.html
|
|
73
|
+
formatter['text/html'] = options.html
|
|
72
74
|
} else {
|
|
73
|
-
let file = options.html[error.code]
|
|
75
|
+
let file = options.html[error.code]
|
|
74
76
|
if (!file) {
|
|
75
|
-
file = options.html.default || defaultHtmlError
|
|
77
|
+
file = options.html.default || defaultHtmlError
|
|
76
78
|
}
|
|
77
79
|
// If the developer passed a custom function for individual html errors
|
|
78
80
|
if (typeof file === 'function') {
|
|
79
|
-
formatter['text/html'] = file
|
|
81
|
+
formatter['text/html'] = file
|
|
80
82
|
} else {
|
|
81
83
|
formatter['text/html'] = function () {
|
|
82
|
-
res.set('Content-Type', 'text/html')
|
|
83
|
-
res.sendFile(file)
|
|
84
|
-
}
|
|
84
|
+
res.set('Content-Type', 'text/html')
|
|
85
|
+
res.sendFile(file)
|
|
86
|
+
}
|
|
85
87
|
}
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
// If the developer passed a custom function for ALL json errors
|
|
89
91
|
if (typeof options.json === 'function') {
|
|
90
|
-
formatter['application/json'] = options.json
|
|
92
|
+
formatter['application/json'] = options.json
|
|
91
93
|
} else {
|
|
92
|
-
const handler = options.json[error.code] || options.json.default
|
|
94
|
+
const handler = options.json[error.code] || options.json.default
|
|
93
95
|
// If the developer passed a custom function for individual json errors
|
|
94
96
|
if (typeof handler === 'function') {
|
|
95
|
-
formatter['application/json'] = handler
|
|
97
|
+
formatter['application/json'] = handler
|
|
96
98
|
} else {
|
|
97
99
|
// Don't show stack trace if it is a 404 error
|
|
98
100
|
if (error.code === 404) {
|
|
99
|
-
error.stack = null
|
|
101
|
+
error.stack = null
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
formatter['application/json'] = function () {
|
|
103
|
-
const output = Object.assign({}, error.toJSON())
|
|
105
|
+
const output = Object.assign({}, error.toJSON())
|
|
104
106
|
|
|
105
107
|
if (process.env.NODE_ENV === 'production') {
|
|
106
|
-
delete output.stack
|
|
108
|
+
delete output.stack
|
|
107
109
|
}
|
|
108
110
|
|
|
109
|
-
res.set('Content-Type', 'application/json')
|
|
110
|
-
res.json(output)
|
|
111
|
-
}
|
|
111
|
+
res.set('Content-Type', 'application/json')
|
|
112
|
+
res.json(output)
|
|
113
|
+
}
|
|
112
114
|
}
|
|
113
115
|
}
|
|
114
116
|
|
|
115
|
-
res.status(error.code)
|
|
117
|
+
res.status(error.code)
|
|
116
118
|
|
|
117
|
-
const contentType = req.headers['content-type'] || ''
|
|
118
|
-
const accepts = req.headers.accept || ''
|
|
119
|
+
const contentType = req.headers['content-type'] || ''
|
|
120
|
+
const accepts = req.headers.accept || ''
|
|
119
121
|
|
|
120
122
|
// by default just send back json
|
|
121
123
|
if (contentType.indexOf('json') !== -1 || accepts.indexOf('json') !== -1) {
|
|
122
|
-
formatter['application/json'](error, req, res, next)
|
|
124
|
+
formatter['application/json'](error, req, res, next)
|
|
123
125
|
} else if (options.html && (contentType.indexOf('html') !== -1 || accepts.indexOf('html') !== -1)) {
|
|
124
|
-
formatter['text/html'](error, req, res, next)
|
|
126
|
+
formatter['text/html'](error, req, res, next)
|
|
125
127
|
} else {
|
|
126
128
|
// TODO (EK): Maybe just return plain text
|
|
127
|
-
formatter['application/json'](error, req, res, next)
|
|
129
|
+
formatter['application/json'](error, req, res, next)
|
|
128
130
|
}
|
|
129
|
-
}
|
|
131
|
+
}
|
|
130
132
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,119 +1,141 @@
|
|
|
1
|
-
import express, { Express } from 'express'
|
|
2
|
-
import { Application as FeathersApplication, defaultServiceMethods } from '@feathersjs/feathers'
|
|
3
|
-
import { routing } from '@feathersjs/transport-commons'
|
|
4
|
-
import { createDebug } from '@feathersjs/commons'
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export
|
|
13
|
-
|
|
1
|
+
import express, { Express } from 'express'
|
|
2
|
+
import { Application as FeathersApplication, defaultServiceMethods } from '@feathersjs/feathers'
|
|
3
|
+
import { routing } from '@feathersjs/transport-commons'
|
|
4
|
+
import { createDebug } from '@feathersjs/commons'
|
|
5
|
+
|
|
6
|
+
import { rest, RestOptions, formatter } from './rest'
|
|
7
|
+
import { errorHandler, notFound, ErrorHandlerOptions } from './handlers'
|
|
8
|
+
import { Application, ExpressOverrides } from './declarations'
|
|
9
|
+
import { AuthenticationSettings, authenticate, parseAuthentication } from './authentication'
|
|
10
|
+
import { default as original, static as serveStatic, json, raw, text, urlencoded, query } from 'express'
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
original,
|
|
14
|
+
serveStatic,
|
|
15
|
+
serveStatic as static,
|
|
16
|
+
json,
|
|
17
|
+
raw,
|
|
18
|
+
text,
|
|
19
|
+
urlencoded,
|
|
20
|
+
query,
|
|
21
|
+
rest,
|
|
22
|
+
RestOptions,
|
|
23
|
+
formatter,
|
|
24
|
+
errorHandler,
|
|
25
|
+
notFound,
|
|
26
|
+
Application,
|
|
27
|
+
ErrorHandlerOptions,
|
|
28
|
+
ExpressOverrides,
|
|
29
|
+
AuthenticationSettings,
|
|
30
|
+
parseAuthentication,
|
|
31
|
+
authenticate
|
|
32
|
+
}
|
|
14
33
|
|
|
15
|
-
const debug = createDebug('@feathersjs/express')
|
|
34
|
+
const debug = createDebug('@feathersjs/express')
|
|
16
35
|
|
|
17
|
-
export default function feathersExpress<S = any, C = any>
|
|
36
|
+
export default function feathersExpress<S = any, C = any>(
|
|
37
|
+
feathersApp?: FeathersApplication<S, C>,
|
|
38
|
+
expressApp: Express = express()
|
|
39
|
+
): Application<S, C> {
|
|
18
40
|
if (!feathersApp) {
|
|
19
|
-
return expressApp as any
|
|
41
|
+
return expressApp as any
|
|
20
42
|
}
|
|
21
43
|
|
|
22
44
|
if (typeof feathersApp.setup !== 'function') {
|
|
23
|
-
throw new Error('@feathersjs/express requires a valid Feathers application instance')
|
|
45
|
+
throw new Error('@feathersjs/express requires a valid Feathers application instance')
|
|
24
46
|
}
|
|
25
47
|
|
|
26
|
-
const app = expressApp as any as Application<S, C
|
|
27
|
-
const { use: expressUse, listen: expressListen } = expressApp as any
|
|
28
|
-
const { use: feathersUse, teardown: feathersTeardown } = feathersApp
|
|
48
|
+
const app = expressApp as any as Application<S, C>
|
|
49
|
+
const { use: expressUse, listen: expressListen } = expressApp as any
|
|
50
|
+
const { use: feathersUse, teardown: feathersTeardown } = feathersApp
|
|
29
51
|
|
|
30
52
|
Object.assign(app, {
|
|
31
|
-
use
|
|
32
|
-
let service: any
|
|
33
|
-
let options = {}
|
|
53
|
+
use(location: string & keyof S, ...rest: any[]) {
|
|
54
|
+
let service: any
|
|
55
|
+
let options = {}
|
|
34
56
|
|
|
35
|
-
const middleware = rest.reduce(
|
|
57
|
+
const middleware = rest.reduce(
|
|
58
|
+
function (middleware, arg) {
|
|
36
59
|
if (typeof arg === 'function' || Array.isArray(arg)) {
|
|
37
|
-
middleware[service ? 'after' : 'before'].push(arg)
|
|
60
|
+
middleware[service ? 'after' : 'before'].push(arg)
|
|
38
61
|
} else if (!service) {
|
|
39
|
-
service = arg
|
|
62
|
+
service = arg
|
|
40
63
|
} else if (arg.methods || arg.events) {
|
|
41
|
-
options = arg
|
|
64
|
+
options = arg
|
|
42
65
|
} else {
|
|
43
|
-
throw new Error('Invalid options passed to app.use')
|
|
66
|
+
throw new Error('Invalid options passed to app.use')
|
|
44
67
|
}
|
|
45
|
-
return middleware
|
|
46
|
-
},
|
|
68
|
+
return middleware
|
|
69
|
+
},
|
|
70
|
+
{
|
|
47
71
|
before: [],
|
|
48
72
|
after: []
|
|
49
|
-
}
|
|
73
|
+
}
|
|
74
|
+
)
|
|
50
75
|
|
|
51
|
-
const hasMethod = (methods: string[]) =>
|
|
52
|
-
(service && typeof service[name] === 'function')
|
|
53
|
-
);
|
|
76
|
+
const hasMethod = (methods: string[]) =>
|
|
77
|
+
methods.some((name) => service && typeof service[name] === 'function')
|
|
54
78
|
|
|
55
79
|
// Check for service (any object with at least one service method)
|
|
56
80
|
if (hasMethod(['handle', 'set']) || !hasMethod(defaultServiceMethods)) {
|
|
57
|
-
debug('Passing app.use call to Express app')
|
|
58
|
-
return expressUse.call(this, location, ...rest)
|
|
81
|
+
debug('Passing app.use call to Express app')
|
|
82
|
+
return expressUse.call(this, location, ...rest)
|
|
59
83
|
}
|
|
60
84
|
|
|
61
|
-
debug('Registering service with middleware', middleware)
|
|
85
|
+
debug('Registering service with middleware', middleware)
|
|
62
86
|
// Since this is a service, call Feathers `.use`
|
|
63
87
|
feathersUse.call(this, location, service, {
|
|
64
88
|
...options,
|
|
65
89
|
express: middleware
|
|
66
|
-
})
|
|
90
|
+
})
|
|
67
91
|
|
|
68
|
-
return this
|
|
92
|
+
return this
|
|
69
93
|
},
|
|
70
94
|
|
|
71
|
-
async listen
|
|
72
|
-
const server = expressListen.call(this, ...args)
|
|
95
|
+
async listen(...args: any[]) {
|
|
96
|
+
const server = expressListen.call(this, ...args)
|
|
73
97
|
|
|
74
|
-
this.server = server
|
|
75
|
-
await this.setup(server)
|
|
76
|
-
debug('Feathers application listening')
|
|
98
|
+
this.server = server
|
|
99
|
+
await this.setup(server)
|
|
100
|
+
debug('Feathers application listening')
|
|
77
101
|
|
|
78
|
-
return server
|
|
102
|
+
return server
|
|
79
103
|
},
|
|
80
104
|
|
|
81
|
-
async teardown
|
|
82
|
-
return feathersTeardown
|
|
83
|
-
|
|
84
|
-
|
|
105
|
+
async teardown(server?: any) {
|
|
106
|
+
return feathersTeardown
|
|
107
|
+
.call(this, server)
|
|
108
|
+
.then(
|
|
109
|
+
() => new Promise((resolve, reject) => this.server.close((e) => (e ? reject(e) : resolve(this))))
|
|
110
|
+
)
|
|
85
111
|
}
|
|
86
|
-
} as Application<S, C>)
|
|
112
|
+
} as Application<S, C>)
|
|
87
113
|
|
|
88
114
|
const appDescriptors = {
|
|
89
115
|
...Object.getOwnPropertyDescriptors(Object.getPrototypeOf(app)),
|
|
90
116
|
...Object.getOwnPropertyDescriptors(app)
|
|
91
|
-
}
|
|
117
|
+
}
|
|
92
118
|
const newDescriptors = {
|
|
93
119
|
...Object.getOwnPropertyDescriptors(Object.getPrototypeOf(feathersApp)),
|
|
94
120
|
...Object.getOwnPropertyDescriptors(feathersApp)
|
|
95
|
-
}
|
|
121
|
+
}
|
|
96
122
|
|
|
97
123
|
// Copy all non-existing properties (including non-enumerables)
|
|
98
124
|
// that don't already exist on the Express app
|
|
99
|
-
Object.keys(newDescriptors).forEach(prop => {
|
|
100
|
-
const appProp = appDescriptors[prop]
|
|
101
|
-
const newProp = newDescriptors[prop]
|
|
125
|
+
Object.keys(newDescriptors).forEach((prop) => {
|
|
126
|
+
const appProp = appDescriptors[prop]
|
|
127
|
+
const newProp = newDescriptors[prop]
|
|
102
128
|
|
|
103
129
|
if (appProp === undefined && newProp !== undefined) {
|
|
104
|
-
Object.defineProperty(expressApp, prop, newProp)
|
|
130
|
+
Object.defineProperty(expressApp, prop, newProp)
|
|
105
131
|
}
|
|
106
|
-
})
|
|
132
|
+
})
|
|
107
133
|
|
|
108
|
-
app.configure(routing() as any)
|
|
109
|
-
app.use((req, _res, next) => {
|
|
110
|
-
req.feathers = { ...req.feathers, provider: 'rest' };
|
|
111
|
-
return next();
|
|
112
|
-
});
|
|
134
|
+
app.configure(routing() as any)
|
|
113
135
|
|
|
114
|
-
return app
|
|
136
|
+
return app
|
|
115
137
|
}
|
|
116
138
|
|
|
117
139
|
if (typeof module !== 'undefined') {
|
|
118
|
-
module.exports = Object.assign(feathersExpress, module.exports)
|
|
140
|
+
module.exports = Object.assign(feathersExpress, module.exports)
|
|
119
141
|
}
|
package/src/rest.ts
CHANGED
|
@@ -1,110 +1,116 @@
|
|
|
1
|
-
import { Request, Response, RequestHandler, Router } from 'express'
|
|
2
|
-
import { MethodNotAllowed } from '@feathersjs/errors'
|
|
3
|
-
import { createDebug } from '@feathersjs/commons'
|
|
4
|
-
import { http } from '@feathersjs/transport-commons'
|
|
5
|
-
import { createContext, defaultServiceMethods, getServiceOptions } from '@feathersjs/feathers'
|
|
1
|
+
import { Request, Response, RequestHandler, Router } from 'express'
|
|
2
|
+
import { MethodNotAllowed } from '@feathersjs/errors'
|
|
3
|
+
import { createDebug } from '@feathersjs/commons'
|
|
4
|
+
import { http } from '@feathersjs/transport-commons'
|
|
5
|
+
import { createContext, defaultServiceMethods, getServiceOptions } from '@feathersjs/feathers'
|
|
6
6
|
|
|
7
|
-
import { AuthenticationSettings, parseAuthentication } from './authentication'
|
|
8
|
-
import { Application } from './declarations'
|
|
7
|
+
import { AuthenticationSettings, parseAuthentication } from './authentication'
|
|
8
|
+
import { Application } from './declarations'
|
|
9
9
|
|
|
10
|
-
const debug = createDebug('@feathersjs/express/rest')
|
|
10
|
+
const debug = createDebug('@feathersjs/express/rest')
|
|
11
11
|
|
|
12
|
-
const toHandler = (
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const toHandler = (
|
|
13
|
+
func: (req: Request, res: Response, next: () => void) => Promise<void>
|
|
14
|
+
): RequestHandler => {
|
|
15
|
+
return (req, res, next) => func(req, res, next).catch((error) => next(error))
|
|
16
|
+
}
|
|
15
17
|
|
|
16
18
|
const serviceMiddleware = (): RequestHandler => {
|
|
17
19
|
return toHandler(async (req, res, next) => {
|
|
18
|
-
const { query, headers, path, body: data, method: httpMethod } = req
|
|
19
|
-
const methodOverride = req.headers[http.METHOD_HEADER] as string | undefined
|
|
20
|
+
const { query, headers, path, body: data, method: httpMethod } = req
|
|
21
|
+
const methodOverride = req.headers[http.METHOD_HEADER] as string | undefined
|
|
20
22
|
|
|
21
|
-
const { service, params: { __id: id = null, ...route } = {} } = req.lookup
|
|
22
|
-
const method = http.getServiceMethod(httpMethod, id, methodOverride)
|
|
23
|
-
const { methods } = getServiceOptions(service)
|
|
23
|
+
const { service, params: { __id: id = null, ...route } = {} } = req.lookup!
|
|
24
|
+
const method = http.getServiceMethod(httpMethod, id, methodOverride)
|
|
25
|
+
const { methods } = getServiceOptions(service)
|
|
24
26
|
|
|
25
|
-
debug(`Found service for path ${path}, attempting to run '${method}' service method`)
|
|
27
|
+
debug(`Found service for path ${path}, attempting to run '${method}' service method`)
|
|
26
28
|
|
|
27
29
|
if (!methods.includes(method) || defaultServiceMethods.includes(methodOverride)) {
|
|
28
|
-
const error = new MethodNotAllowed(`Method \`${method}\` is not supported by this endpoint.`)
|
|
29
|
-
res.statusCode = error.code
|
|
30
|
-
throw error
|
|
30
|
+
const error = new MethodNotAllowed(`Method \`${method}\` is not supported by this endpoint.`)
|
|
31
|
+
res.statusCode = error.code
|
|
32
|
+
throw error
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
const createArguments = http.argumentsFor[method as 'get'] || http.argumentsFor.default
|
|
34
|
-
const params = { query, headers, route, ...req.feathers }
|
|
35
|
-
const args = createArguments({ id, data, params })
|
|
36
|
-
const contextBase = createContext(service, method, { http: {} })
|
|
37
|
-
res.hook = contextBase
|
|
35
|
+
const createArguments = http.argumentsFor[method as 'get'] || http.argumentsFor.default
|
|
36
|
+
const params = { query, headers, route, ...req.feathers }
|
|
37
|
+
const args = createArguments({ id, data, params })
|
|
38
|
+
const contextBase = createContext(service, method, { http: {} })
|
|
39
|
+
res.hook = contextBase
|
|
38
40
|
|
|
39
|
-
const context = await (service as any)[method](...args, contextBase)
|
|
40
|
-
res.hook = context
|
|
41
|
+
const context = await (service as any)[method](...args, contextBase)
|
|
42
|
+
res.hook = context
|
|
41
43
|
|
|
42
|
-
const response = http.getResponse(context)
|
|
43
|
-
res.statusCode = response.status
|
|
44
|
-
res.set(response.headers)
|
|
45
|
-
res.data = response.body
|
|
44
|
+
const response = http.getResponse(context)
|
|
45
|
+
res.statusCode = response.status
|
|
46
|
+
res.set(response.headers)
|
|
47
|
+
res.data = response.body
|
|
46
48
|
|
|
47
|
-
return next()
|
|
48
|
-
})
|
|
49
|
-
}
|
|
49
|
+
return next()
|
|
50
|
+
})
|
|
51
|
+
}
|
|
50
52
|
|
|
51
53
|
const servicesMiddleware = (): RequestHandler => {
|
|
52
54
|
return toHandler(async (req, res, next) => {
|
|
53
|
-
const app = req.app as any as Application
|
|
54
|
-
const lookup = app.lookup(req.path)
|
|
55
|
+
const app = req.app as any as Application
|
|
56
|
+
const lookup = app.lookup(req.path)
|
|
55
57
|
|
|
56
58
|
if (!lookup) {
|
|
57
|
-
return next()
|
|
59
|
+
return next()
|
|
58
60
|
}
|
|
59
61
|
|
|
60
|
-
req.lookup = lookup
|
|
62
|
+
req.lookup = lookup
|
|
61
63
|
|
|
62
|
-
const options = getServiceOptions(lookup.service)
|
|
63
|
-
const middleware = options.express
|
|
64
|
+
const options = getServiceOptions(lookup.service)
|
|
65
|
+
const middleware = options.express.composed
|
|
64
66
|
|
|
65
|
-
return middleware(req, res, next)
|
|
66
|
-
})
|
|
67
|
-
}
|
|
67
|
+
return middleware(req, res, next)
|
|
68
|
+
})
|
|
69
|
+
}
|
|
68
70
|
|
|
69
71
|
export const formatter: RequestHandler = (_req, res, next) => {
|
|
70
72
|
if (res.data === undefined) {
|
|
71
|
-
return next()
|
|
73
|
+
return next()
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
res.format({
|
|
75
|
-
'application/json'
|
|
76
|
-
res.json(res.data)
|
|
77
|
+
'application/json'() {
|
|
78
|
+
res.json(res.data)
|
|
77
79
|
}
|
|
78
|
-
})
|
|
79
|
-
}
|
|
80
|
+
})
|
|
81
|
+
}
|
|
80
82
|
|
|
81
83
|
export type RestOptions = {
|
|
82
|
-
formatter?: RequestHandler
|
|
83
|
-
authentication?: AuthenticationSettings
|
|
84
|
-
}
|
|
84
|
+
formatter?: RequestHandler
|
|
85
|
+
authentication?: AuthenticationSettings
|
|
86
|
+
}
|
|
85
87
|
|
|
86
88
|
export const rest = (options?: RestOptions | RequestHandler) => {
|
|
87
|
-
options = typeof options === 'function' ? { formatter: options } : options || {}
|
|
89
|
+
options = typeof options === 'function' ? { formatter: options } : options || {}
|
|
88
90
|
|
|
89
|
-
const formatterMiddleware = options.formatter || formatter
|
|
90
|
-
const authenticationOptions = options.authentication
|
|
91
|
+
const formatterMiddleware = options.formatter || formatter
|
|
92
|
+
const authenticationOptions = options.authentication
|
|
91
93
|
|
|
92
94
|
return (app: Application) => {
|
|
93
95
|
if (typeof app.route !== 'function') {
|
|
94
|
-
throw new Error('@feathersjs/express/rest needs an Express compatible app.')
|
|
96
|
+
throw new Error('@feathersjs/express/rest needs an Express compatible app.')
|
|
95
97
|
}
|
|
96
98
|
|
|
97
|
-
app.use(
|
|
98
|
-
|
|
99
|
+
app.use((req, _res, next) => {
|
|
100
|
+
req.feathers = { ...req.feathers, provider: 'rest' }
|
|
101
|
+
return next()
|
|
102
|
+
})
|
|
103
|
+
app.use(parseAuthentication(authenticationOptions))
|
|
104
|
+
app.use(servicesMiddleware())
|
|
99
105
|
|
|
100
106
|
app.mixins.push((_service, _path, options) => {
|
|
101
|
-
const { express: { before = [], after = [] } = {} } = options
|
|
107
|
+
const { express: { before = [], after = [] } = {} } = options
|
|
102
108
|
|
|
103
|
-
const middlewares = [].concat(before, serviceMiddleware(), after, formatterMiddleware)
|
|
104
|
-
const middleware = Router().use(middlewares)
|
|
109
|
+
const middlewares = [].concat(before, serviceMiddleware(), after, formatterMiddleware)
|
|
110
|
+
const middleware = Router().use(middlewares)
|
|
105
111
|
|
|
106
|
-
options.express ||= {}
|
|
107
|
-
options.express.composed = middleware
|
|
108
|
-
})
|
|
109
|
-
}
|
|
112
|
+
options.express ||= {}
|
|
113
|
+
options.express.composed = middleware
|
|
114
|
+
})
|
|
115
|
+
}
|
|
110
116
|
}
|