@steedos/service-api 2.5.3-beta.21 → 2.5.3-beta.23

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.
Files changed (2) hide show
  1. package/index.js +82 -30
  2. 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),
@@ -204,6 +201,85 @@ module.exports = {
204
201
  // Enable/disable logging
205
202
  logging: false,
206
203
 
204
+ // Route error handler
205
+ onError(req, res, err) {
206
+ res.setHeader("Content-Type", "application/json; charset=utf-8");
207
+ res.writeHead(err.code || 500);
208
+ res.end(JSON.stringify({ error: err.message, detail: err }));
209
+ }
210
+ },
211
+ {
212
+ path: "/api/v1",
213
+
214
+ whitelist: [
215
+ "**",
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
+
207
283
  // Route error handler
208
284
  onError(req, res, err) {
209
285
  res.setHeader("Content-Type", "application/json; charset=utf-8");
@@ -732,30 +808,6 @@ module.exports = {
732
808
  created() {
733
809
  this.app = SteedosRouter.staticRouter();
734
810
  },
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
811
  async started() {
760
812
 
761
813
  this.broker.createService(require("@steedos/service-ui"));
@@ -772,9 +824,9 @@ module.exports = {
772
824
  // });
773
825
  // }
774
826
 
775
- // this.broker.waitForServices('~packages-@steedos/service-ui').then(() => {
776
- // this.app.use("/", this.express());
777
- // })
827
+ this.broker.waitForServices('~packages-@steedos/service-ui').then(() => {
828
+ this.app.use("/", this.express());
829
+ })
778
830
 
779
831
  global.SteedosApi = {
780
832
  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.21",
3
+ "version": "2.5.3-beta.23",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
7
- "@steedos/auth": "2.5.3-beta.21",
8
- "@steedos/router": "2.5.3-beta.21",
9
- "@steedos/service-object-graphql": "2.5.3-beta.21",
10
- "@steedos/service-ui": "2.5.3-beta.21",
7
+ "@steedos/auth": "2.5.3-beta.23",
8
+ "@steedos/router": "2.5.3-beta.23",
9
+ "@steedos/service-object-graphql": "2.5.3-beta.23",
10
+ "@steedos/service-ui": "2.5.3-beta.23",
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": "b4313a2ef5d18ef1cf9271bd3c89b2d6fe52d65b"
22
+ "gitHead": "8fd9cf35d29f8f71e11790bd010bf5b045e7ebc4"
23
23
  }