javascript - In node.js, is there an alternative to variables that may require global access?
高洛峰
高洛峰 2017-05-31 10:41:14
0
3
680

I am developing a forum, and now I propose this function:
The super administrator must be able to switch some functions of the forum, such as posting, registration, etc.
At my own level, I only think of global variables. , is there an alternative?
The framework is express

Supplement:
The current method that comes to mind is to define some variables globally such as

global.__POST = true //可以发帖
//然后管理页面增加个按钮什么的  请求一个操作
//然后权限审核
...
global.__POST = false //关闭

Then confirm first when the user posts if(global.__POST)

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(3)
小葫芦

This configuration can be extracted into a public site configuration file, such as adding a global-config.json to the project, with the content in the form:

{
  "allowRegister": true,
  "allowNewPost": false
}

Then, add the special API corresponding to the administrator account, and the configuration file can be modified through the administrator API. For general users, the configuration file is read when the page is loaded, and the display logic of related functions is determined based on the parameters persisted in the configuration file.

黄舟

Users of different levels have different permissions. Many websites have such a design. I don’t quite understand what you mean by global variables. Could you explain your idea in more detail

滿天的星座

global is at the application layer and is shared by everyone. You shouldn’t use him to operate it

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template