当前位置: 首页 > 软件库 > Web应用开发 > >

rbac-mern-boilerplate

授权协议 MIT License
开发语言 JavaScript
所属分类 Web应用开发
软件类型 开源软件
地区 不详
投 递 者 笪烨
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Welcome to the RBAC MERN Boilerplate project

A MERN boilerplate repository with RBAC feature, following all production best practices.

In this repository I will keep adding the production best practices we should follow in a MERN (MongoDB, Express.js, React.js, and Node.js) project.

Technology stack

As the name suggests, this repository is built on top of Express.js and React.js, however in the implementation detail, we will find other supporting technologies as well.

Client side

  • React - A JavaScript library for building user interfaces
  • MongoDB - The application data platform
  • Ant Design - A design system for enterprise-level products. Create an efficient and enjoyable work experience
  • Testing Library - React Testing Library
  • Axios - Promise based HTTP client for the browser and node.js
  • Styled Components - Visual primitives for the component age

Server side

Details frameworks and packages can be found in the package.json files in server and client directory.

Run the application

This project can be run basically in two ways. One is using docker, other way is to run manually via vscode.

Docker

Prerequisites
  • Docker : To run docker-compose command

Go to the root of the repository and execute npm start. This will spin up the server and client containers along with the MongoDB instance inside of Docker environment.

cd project-root
npm start

Visual Studio Code

Prerequisites
  • Node.js : To run npm packages
  • Docker : To run MongoDB database
Steps
  • To run via vscode, we should run the server and client side projects separately, and also make sure mongodb is up and running.
  • Create a .env file inside of the server directory. Add the below entries
    DB_HOST=localhost
    DB_PORT=27017
    DB_NAME=appdb
    

Server commands

cd server
npm i
npm run db:up
npm start

Client commands

cd client
npm i
npm start

Test client app

To view the client, open your browser and visit http://localhost:3000 url.For the demo purpose, the authentication and authorization is not controlled from database entry and purely handled in client side.

The system has a role-based-access-control system which is controlled by permissions assigned to the role.The system supports different types of permissions in the client side.Depending on the role, side menu, the actual page (route) can be visible or not. More of that, any individual control/components can also be enabled / disabled depending on the role as well.

Superman in the role of SuperAdmin

To login as SuperAdmin we input superadmin@example.com as email and put anything as the password.Upon login, the user should see superadmin's menus (Role, User, Resource, Permission) at the left side.

Pikachu in the role of User

To login as User, we input any valid email and anything as password.Upon login, the user should see menus (Product, Customer) at the left side.

Change the permissions

Ideally we should handle the permissions in server side and store in database (mongodb), but for this demo, we will modify the data in the clint side and mimic the server side behavior.To change User's permission, go to client/src/data/user-pikachu.json and add/update entry in the permissions array.A sample permission entry is like

{
  "_id": "5c8d03505653de3f85aa1ff",
  "resourceName": "customers-add",
  "resourceType": "route",
  "isAllowed": true,
  "isDisabled": false
}

To disable a button, we can set isDisabled = true like below

{
  "_id": "5c8d0c505653de3985aa0f1",
  "resourceName": "product-edit-button",
  "resourceType": "button",
  "isAllowed": true,
  "isDisabled": true
}

Centralized log to Sentry.io

We can also send the logs to sentry.io. To use this feature, we need to add the dsn entry into client/src/env.config.js.Setup snippet is like below in index.js file

Sentry.init({
  dsn: Config.dsn,
  integrations: [new Integrations.BrowserTracing()],
  tracesSampleRate: 1.0,
});

Test server API

To view the api, open your browser and visit http://localhost:5000/api-docsIdeally we should add all of the API endpoints into the swagger, but for the demo purpose, we only added Products API endpoint.
To test the APIs, we can reuse the postman collection. Open docs/rbac-mern-boilerplate.postman_collection.json into Postman and you should see the endpoints with appropriate payloads.

Scripts

Project Command Task
root npm run build Builds the containers
root npm run start Start the projects and database in docker containers
root docker exec -it appserver /bin/sh then npm run db:seed Executes seed products inside container
server npm i Install server side dependencies
server npm run db:up Start the database in a docker container
server npm run db:seed Seed products data into database
server npm run test Execute tests using jest
client npm i Install client side dependencies
client npm run start Start the react app
client npm run build Build the react app in production mode
client npm run test Execute tests using Testing Library

Types of testing

In this repository, we have included both unit testing and integration testing. For now, the code coverage is very low, but we are working on it to make it more than 90% somewhere in the future

Client side

  • We incorporated only unit tests in client side, and mock all the externals dependencies like localStorage and axios.

To run the tests, we can run npm run test command.

Server side

  • Integration testing: We have integrated the Jest as the testing library, and we have added supertest and mongodb-memory-server packages to make the integration testing easier.
  • Unit testing: We have used Jest to test the service layers and mock the external dependencies like MongoDB.

To run the tests, we can run npm run test command.

License

This project is MIT licensed.

 相关资料
  • MERN-boilerplate This is a boilerplate project using the following technologies: React and React Router for the frontend Express and Mongoose for the backend Sass for styles (using the SCSS syntax) We

  • RBAC管理器就是为了让 RBAC 管理员能够更加轻松的工具。它提供了一个GUI界面能方便的编辑 RBAC 设置 Exchange 2010 系统;包括增加删除 cmdlets, cmdlets 属性以及委派任务等等。

  • 类似 Mean,是另一个全栈 Javascript 开发架构,使用 MongoDB,Express,React,Node。 特性 React 组件的热加载 模块化文件结构 使用 React 路由器进行代码拆分 Ava 测试运行(并行运行测试) 国际化支持 支持 Docker 支持代码生成 搭建自己的 MERN 下面是两个启动工具 MERN Starter git clone https://git

  • 前面两节课我们学习了Kubernetes中的两个用于配置信息的重要资源对象:ConfigMap和Secret,其实到这里我们基本上学习的内容已经覆盖到Kubernetes中一些重要的资源对象了,来部署一个应用程序是完全没有问题的了。在我们演示一个完整的示例之前,我们还需要给大家讲解一个重要的概念:RBAC - 基于角色的访问控制。 RBAC使用rbac.authorization.k8s.io A

  • 一个更友好的RBAC API。 这个API是Management API的子集。 RBAC用户可以使用这个API来简化代码。 参考 全局变量 e是实施者实例。GoNode.jsPHP.NETRust e, err := NewEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv") const e = await newEn

  • Description The rbac module for Nest. Installation npm i --save nestjs-rbac Quick Start For using RBAC there is need to implement IStorageRbac export interface IStorageRbac { roles: string[]; permis