🪛 Tweaks

This commit is contained in:
2021-06-27 15:24:42 -07:00
parent dd3033177b
commit d46c2aedbb
2 changed files with 42 additions and 85 deletions

View File

@@ -1,5 +1,10 @@
"use strict"; "use strict";
import {BrokerOptions, Errors, MetricRegistry, ServiceBroker} from "moleculer"; import {
BrokerOptions,
Errors,
MetricRegistry,
ServiceBroker,
} from "moleculer";
/** /**
* Moleculer ServiceBroker configuration file * Moleculer ServiceBroker configuration file
@@ -63,7 +68,7 @@ const brokerConfig: BrokerOptions = {
// Define a cacher. // Define a cacher.
// More info: https://moleculer.services/docs/0.14/caching.html // More info: https://moleculer.services/docs/0.14/caching.html
cacher: "Memory", cacher: "Memory",
// Define a serializer. // Define a serializer.
// Available values: "JSON", "Avro", "ProtoBuf", "MsgPack", "Notepack", "Thrift". // Available values: "JSON", "Avro", "ProtoBuf", "MsgPack", "Notepack", "Thrift".
@@ -153,7 +158,7 @@ const brokerConfig: BrokerOptions = {
// Enable/disable built-in metrics function. More info: https://moleculer.services/docs/0.14/metrics.html // Enable/disable built-in metrics function. More info: https://moleculer.services/docs/0.14/metrics.html
metrics: { metrics: {
enabled: true, enabled: false,
// Available built-in reporters: "Console", "CSV", "Event", "Prometheus", "Datadog", "StatsD" // Available built-in reporters: "Console", "CSV", "Event", "Prometheus", "Datadog", "StatsD"
reporter: { reporter: {
type: "Console", type: "Console",
@@ -180,12 +185,12 @@ const brokerConfig: BrokerOptions = {
options: { options: {
// Custom logger // Custom logger
logger: null, logger: null,
// Using colors // Using colors
colors: true, colors: true,
// Width of row // Width of row
width: 100, width: 100,
// Gauge width in the row // Gauge width in the row
gaugeWidth: 40, gaugeWidth: 40,
}, },
}, },
}, },
@@ -202,7 +207,6 @@ const brokerConfig: BrokerOptions = {
started: async (broker: ServiceBroker): Promise<void> => {}, started: async (broker: ServiceBroker): Promise<void> => {},
stopped: async (broker: ServiceBroker): Promise<void> => {}, stopped: async (broker: ServiceBroker): Promise<void> => {},
*/ */
}; };
export = brokerConfig; export = brokerConfig;

View File

@@ -1,9 +1,8 @@
import {IncomingMessage} from "http"; import { IncomingMessage } from "http";
import {Service, ServiceBroker, Context} from "moleculer"; import { Service, ServiceBroker, Context } from "moleculer";
import ApiGateway from "moleculer-web"; import ApiGateway from "moleculer-web";
export default class ApiService extends Service { export default class ApiService extends Service {
public constructor(broker: ServiceBroker) { public constructor(broker: ServiceBroker) {
super(broker); super(broker);
// @ts-ignore // @ts-ignore
@@ -12,94 +11,50 @@ export default class ApiService extends Service {
mixins: [ApiGateway], mixins: [ApiGateway],
// More info about settings: https://moleculer.services/docs/0.14/moleculer-web.html // More info about settings: https://moleculer.services/docs/0.14/moleculer-web.html
settings: { settings: {
port: process.env.PORT || 3000, port: process.env.PORT || 3080,
routes: [{ routes: [
path: "/api", {
whitelist: [ path: "/api",
// Access to any actions in all services under "/api" URL whitelist: ["**"],
"**", use: [],
], mergeParams: true,
// Route-level Express middlewares. More info: https://moleculer.services/docs/0.14/moleculer-web.html#Middlewares
use: [],
// Enable/disable parameter merging method. More info: https://moleculer.services/docs/0.14/moleculer-web.html#Disable-merging
mergeParams: true,
// Enable authentication. Implement the logic into `authenticate` method. More info: https://moleculer.services/docs/0.14/moleculer-web.html#Authentication authentication: false,
authentication: false, authorization: false,
autoAliases: true,
// Enable authorization. Implement the logic into `authorize` method. More info: https://moleculer.services/docs/0.14/moleculer-web.html#Authorization aliases: {},
authorization: false, callingOptions: {},
// The auto-alias feature allows you to declare your route alias directly in your services. bodyParsers: {
// The gateway will dynamically build the full routes from service schema. json: {
autoAliases: true, strict: false,
limit: "1MB",
aliases:{}, },
/** urlencoded: {
* Before call hook. You can check the request. extended: true,
* @param {Context} ctx limit: "1MB",
* @param {Object} route },
* @param {IncomingMessage} req
* @param {ServerResponse} res
* @param {Object} data
onBeforeCall(ctx: Context<any,{userAgent: string}>,
route: object, req: IncomingMessage, res: ServerResponse) {
Set request headers to context meta
ctx.meta.userAgent = req.headers["user-agent"];
},
*/
/**
* After call hook. You can modify the data.
* @param {Context} ctx
* @param {Object} route
* @param {IncomingMessage} req
* @param {ServerResponse} res
* @param {Object} data
*
onAfterCall(ctx: Context, route: object, req: IncomingMessage, res: ServerResponse, data: object) {
// Async function which return with Promise
return doSomething(ctx, res, data);
},
*/
// Calling options. More info: https://moleculer.services/docs/0.14/moleculer-web.html#Calling-options
callingOptions: {},
bodyParsers: {
json: {
strict: false,
limit: "1MB",
},
urlencoded: {
extended: true,
limit: "1MB",
}, },
mappingPolicy: "all", // Available values: "all", "restrict"
// Enable/disable logging
logging: true,
}, },
],
// Mapping policy setting. More info: https://moleculer.services/docs/0.14/moleculer-web.html#Mapping-policy
mappingPolicy: "all", // Available values: "all", "restrict"
// Enable/disable logging
logging: true,
}],
// Do not log client side errors (does not log an error response when the error.code is 400<=X<500) // Do not log client side errors (does not log an error response when the error.code is 400<=X<500)
log4XXResponses: false, log4XXResponses: false,
// Logging the request parameters. Set to any log level to enable it. E.g. "info" // Logging the request parameters. Set to any log level to enable it. E.g. "info"
logRequestParams: null, logRequestParams: null,
// Logging the response data. Set to any log level to enable it. E.g. "info"
logResponseData: null, logResponseData: null,
// Serve assets from "public" folder
assets: { assets: {
folder: "public", folder: "public",
// Options to `server-static` module
options: {}, options: {},
}, },
}, },
methods: { methods: {
/** /**
* Authenticate the request. It checks the `Authorization` token value in the request header. * Authenticate the request. It checks the `Authorization` token value in the request header.
* Check the token value & resolve the user by the token. * Check the token value & resolve the user by the token.
@@ -141,7 +96,6 @@ export default class ApiService extends Service {
} }
}, },
*/ */
/** /**
* Authorize the request. Check that the authenticated user has right to access the resource. * Authorize the request. Check that the authenticated user has right to access the resource.
* *
@@ -168,7 +122,6 @@ export default class ApiService extends Service {
}, },
*/ */
}, },
}); });
} }
} }