How to use moleculer-web - 7 common examples

To help you get started, we’ve selected a few moleculer-web examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gothinkster / moleculer-node-realworld-example-app / services / api.service.js View on Github external
"use strict";

const _ = require("lodash");
const ApiGateway = require("moleculer-web");
const { UnAuthorizedError } = ApiGateway.Errors;

module.exports = {
	name: "api",
	mixins: [ApiGateway],

	settings: {
		port: process.env.PORT || 3000,

		routes: [{
			path: "/api",

			authorization: true,

			aliases: {
				// Login
				"POST /users/login": "users.login",
github icebob / kantab / backend / mixins / openapi.mixin.js View on Github external
created() {
			const route = _.defaultsDeep(mixinOptions.routeOptions, {
				use: [
					ApiGateway.serveStatic(SwaggerUI.absolutePath())
				],

				aliases: {

					"GET /openapi.json"(req, res) {
						// Send back the generated schema
						if (shouldUpdateSchema || !schema) {
							// Create new server & regenerate GraphQL schema
							this.logger.info("♻ Regenerate OpenAPI/Swagger schema...");

							try {
								schema = this.generateOpenAPISchema();

								shouldUpdateSchema = false;

								this.logger.debug(schema);
github icebob / kantab / backend / services / api.service.js View on Github external
/**
			 * Static routes
			 */
			{
				path: "/",

				use: [
					// handle fallback for HTML5 history API
					require("connect-history-api-fallback")(),

					// Webpack middlewares
					...initWebpackMiddlewares(),

					// Serve static
					ApiGateway.serveStatic("./static"),
				],

				// Action aliases
				aliases: {
				},

				mappingPolicy: "restrict",
			},
		]
	},

	methods: {
		/**
		 * Authenticate from request
		 *
		 * @param {Context} ctx
github gothinkster / moleculer-node-realworld-example-app / services / comments.service.js View on Github external
"use strict";

const { ForbiddenError } = require("moleculer-web").Errors;
const DbService = require("moleculer-db");

module.exports = {
	name: "comments",
	mixins: [DbService],
	adapter: new DbService.MemoryAdapter({ filename: "./data/comments.db" }),

	/**
	 * Default settings
	 */
	settings: {
		fields: ["_id", "author", "article", "body", "createdAt", "updatedAt"],
		populates: {
			"author": {
				action: "users.get",
				params: {
github gothinkster / moleculer-node-realworld-example-app / services / articles.service.js View on Github external
"use strict";

const { MoleculerClientError } = require("moleculer").Errors;
const { ForbiddenError } = require("moleculer-web").Errors;

const _ = require("lodash");
const slug = require("slug");
const DbService = require("moleculer-db");

module.exports = {
	name: "articles",
	mixins: [DbService],
	adapter: new DbService.MemoryAdapter({ filename: "./data/articles.db" }),

	/**
	 * Default settings
	 */
	settings: {
		fields: ["_id", "title", "slug", "description", "body", "tagList", "createdAt", "updatedAt", "favorited", "favoritesCount", "author", "comments"],
github gothinkster / moleculer-node-realworld-example-app / services / articles.service.js View on Github external
.then(entity => {
						if (!entity)
							return this.Promise.reject(new MoleculerClientError("Article not found!", 404));

						if (entity.author !== ctx.meta.user._id)
							return this.Promise.reject(new ForbiddenError());

						return this.adapter.removeById(entity._id)
							.then(() => ctx.call("favorites.removeByArticle", { article: entity._id }));
					});
			}
github gothinkster / moleculer-node-realworld-example-app / services / comments.service.js View on Github external
.then(comment => {
						if (comment.author !== ctx.meta.user._id)
							return this.Promise.reject(new ForbiddenError());

						return this.adapter.removeById(ctx.params.id);
					});	
			}

moleculer-web

Official API Gateway service for Moleculer framework

MIT
Latest version published 1 year ago

Package Health Score

63 / 100
Full package analysis