@steedos/service-api 2.5.3-beta.22 → 2.5.3-beta.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/index.js +86 -30
- package/package.json +6 -6
package/index.js
CHANGED
|
@@ -13,8 +13,6 @@ const {
|
|
|
13
13
|
const SteedosRouter = require('@steedos/router');
|
|
14
14
|
const _ = require('lodash');
|
|
15
15
|
const ServiceObjectGraphql = require('@steedos/service-object-graphql')
|
|
16
|
-
const open = require('open');
|
|
17
|
-
|
|
18
16
|
|
|
19
17
|
const mixinOptions = {
|
|
20
18
|
|
|
@@ -92,7 +90,6 @@ const mixinOptions = {
|
|
|
92
90
|
*/
|
|
93
91
|
module.exports = {
|
|
94
92
|
name: "api",
|
|
95
|
-
projectStarted: false,
|
|
96
93
|
mixins: [ApiGateway,
|
|
97
94
|
// GraphQL Apollo Server
|
|
98
95
|
ApolloService(mixinOptions),
|
|
@@ -210,6 +207,89 @@ module.exports = {
|
|
|
210
207
|
res.writeHead(err.code || 500);
|
|
211
208
|
res.end(JSON.stringify({ error: err.message, detail: err }));
|
|
212
209
|
}
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
path: "/api/v1",
|
|
213
|
+
|
|
214
|
+
whitelist: [
|
|
215
|
+
"rest.*",
|
|
216
|
+
],
|
|
217
|
+
|
|
218
|
+
// Route-level Express middlewares. More info: https://moleculer.services/docs/0.14/moleculer-web.html#Middlewares
|
|
219
|
+
use: [],
|
|
220
|
+
|
|
221
|
+
// Enable/disable parameter merging method. More info: https://moleculer.services/docs/0.14/moleculer-web.html#Disable-merging
|
|
222
|
+
mergeParams: true,
|
|
223
|
+
|
|
224
|
+
// Enable authentication. Implement the logic into `authenticate` method. More info: https://moleculer.services/docs/0.14/moleculer-web.html#Authentication
|
|
225
|
+
authentication: true,
|
|
226
|
+
|
|
227
|
+
// Enable authorization. Implement the logic into `authorize` method. More info: https://moleculer.services/docs/0.14/moleculer-web.html#Authorization
|
|
228
|
+
authorization: true,
|
|
229
|
+
|
|
230
|
+
// The auto-alias feature allows you to declare your route alias directly in your services.
|
|
231
|
+
// The gateway will dynamically build the full routes from service schema.
|
|
232
|
+
autoAliases: true,
|
|
233
|
+
|
|
234
|
+
aliases: {
|
|
235
|
+
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Before call hook. You can check the request.
|
|
240
|
+
* @param {Context} ctx
|
|
241
|
+
* @param {Object} route
|
|
242
|
+
* @param {IncomingRequest} req
|
|
243
|
+
* @param {ServerResponse} res
|
|
244
|
+
* @param {Object} data
|
|
245
|
+
*
|
|
246
|
+
onBeforeCall(ctx, route, req, res) {
|
|
247
|
+
// Set request headers to context meta
|
|
248
|
+
ctx.meta.userAgent = req.headers["user-agent"];
|
|
249
|
+
}, */
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* After call hook. You can modify the data.
|
|
253
|
+
* @param {Context} ctx
|
|
254
|
+
* @param {Object} route
|
|
255
|
+
* @param {IncomingRequest} req
|
|
256
|
+
* @param {ServerResponse} res
|
|
257
|
+
* @param {Object} data
|
|
258
|
+
onAfterCall(ctx, route, req, res, data) {
|
|
259
|
+
// Async function which return with Promise
|
|
260
|
+
return doSomething(ctx, res, data);
|
|
261
|
+
}, */
|
|
262
|
+
|
|
263
|
+
// Calling options. More info: https://moleculer.services/docs/0.14/moleculer-web.html#Calling-options
|
|
264
|
+
callingOptions: {},
|
|
265
|
+
|
|
266
|
+
bodyParsers: {
|
|
267
|
+
json: {
|
|
268
|
+
strict: false,
|
|
269
|
+
limit: "10MB"
|
|
270
|
+
},
|
|
271
|
+
urlencoded: {
|
|
272
|
+
extended: true,
|
|
273
|
+
limit: "10MB"
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
|
|
277
|
+
// Mapping policy setting. More info: https://moleculer.services/docs/0.14/moleculer-web.html#Mapping-policy
|
|
278
|
+
mappingPolicy: "all", // Available values: "all", "restrict"
|
|
279
|
+
|
|
280
|
+
// Enable/disable logging
|
|
281
|
+
logging: false,
|
|
282
|
+
|
|
283
|
+
// Route error handler
|
|
284
|
+
onError(req, res, err) {
|
|
285
|
+
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
286
|
+
res.writeHead(err.code || 500);
|
|
287
|
+
res.end(JSON.stringify({
|
|
288
|
+
"status": -1,
|
|
289
|
+
"msg": err.message,
|
|
290
|
+
"data": {}
|
|
291
|
+
}));
|
|
292
|
+
}
|
|
213
293
|
}
|
|
214
294
|
],
|
|
215
295
|
|
|
@@ -732,30 +812,6 @@ module.exports = {
|
|
|
732
812
|
created() {
|
|
733
813
|
this.app = SteedosRouter.staticRouter();
|
|
734
814
|
},
|
|
735
|
-
events:{
|
|
736
|
-
'service-ui.started': function(){
|
|
737
|
-
this.app.use("/", this.express());
|
|
738
|
-
},
|
|
739
|
-
"$packages.changed": function(){
|
|
740
|
-
if (!this.projectStarted) {
|
|
741
|
-
this.projectStarted = true
|
|
742
|
-
// 开发环境, 显示耗时
|
|
743
|
-
if(process.env.NODE_ENV == 'development' && global.__startDate){
|
|
744
|
-
console.log('耗时: ' + (new Date().getTime() - global.__startDate.getTime()) + ' ms');
|
|
745
|
-
}
|
|
746
|
-
console.log(`Project is running at ${process.env.ROOT_URL}`);
|
|
747
|
-
console.log('');
|
|
748
|
-
if (process.env.STEEDOS_AUTO_OPEN_BROWSER != 'false') { // 默认打开,如果不想打开,设置STEEDOS_AUTO_OPEN_BROWSER=false
|
|
749
|
-
try {
|
|
750
|
-
open(process.env.ROOT_URL);
|
|
751
|
-
} catch (error) {
|
|
752
|
-
console.error(error);
|
|
753
|
-
console.error('auto open browser failed.');
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
},
|
|
759
815
|
async started() {
|
|
760
816
|
|
|
761
817
|
this.broker.createService(require("@steedos/service-ui"));
|
|
@@ -772,9 +828,9 @@ module.exports = {
|
|
|
772
828
|
// });
|
|
773
829
|
// }
|
|
774
830
|
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
831
|
+
this.broker.waitForServices('~packages-@steedos/service-ui').then(() => {
|
|
832
|
+
this.app.use("/", this.express());
|
|
833
|
+
})
|
|
778
834
|
|
|
779
835
|
global.SteedosApi = {
|
|
780
836
|
express: this.express
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/service-api",
|
|
3
|
-
"version": "2.5.3-beta.
|
|
3
|
+
"version": "2.5.3-beta.25",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@steedos/auth": "2.5.3-beta.
|
|
8
|
-
"@steedos/router": "2.5.3-beta.
|
|
9
|
-
"@steedos/service-object-graphql": "2.5.3-beta.
|
|
10
|
-
"@steedos/service-ui": "2.5.3-beta.
|
|
7
|
+
"@steedos/auth": "2.5.3-beta.25",
|
|
8
|
+
"@steedos/router": "2.5.3-beta.25",
|
|
9
|
+
"@steedos/service-object-graphql": "2.5.3-beta.25",
|
|
10
|
+
"@steedos/service-ui": "2.5.3-beta.25",
|
|
11
11
|
"graphql": "^15.8.0",
|
|
12
12
|
"graphql-iso-date": "^3.6.1",
|
|
13
13
|
"graphql-type-json": "^0.3.2",
|
|
@@ -19,5 +19,5 @@
|
|
|
19
19
|
"publishConfig": {
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "02543361b65c5eabe667a581687f13fde3b358a8"
|
|
23
23
|
}
|