仪表盘配置指南

Parse仪表盘是一个单独的应用,用来管理Parse Server 应用。Parse仪表盘GitHub地址

安装

  1. npm install -g parse-dashboard

你可以通过在命令行中提供app ID、master key、URL、appName来启动仪表盘:

  1. parse-dashboard --appId yourAppId --masterKey yourMasterKey --serverURL "https://example.com/parse" --appName optionalName

你还可以通过—host、—port、—mountPath来指定主机、端口和挂载路径,你可以使用任何值作为appName,如果没有指定,默认将会使用appID。

启动完成后,你可以通过http://localhost:4040访问 仪表盘。

仪表盘配置指南 - 图1

配置

文件

你也可以在命令行中使用配置文件来启动仪表盘,只需要在你的仪表盘项目目录创建一个parse-dashboard-config.json的文件,并符合下面的格式:

  1. {
  2. "apps": [
  3. {
  4. "serverURL": "http://localhost:1337/parse",
  5. "appId": "myAppId",
  6. "masterKey": "myMasterKey",
  7. "appName": "MyApp"
  8. }
  9. ]
  10. }

然后你就可以使用parse-dashboard --config parse-dashboard-config.json命令来启动仪表盘了。

环境变量

这只在parse-dashboard命令行中可用。

有两种方法可以让你配置仪表盘的环境变量。

多应用

PARSE_DASHBOARD_CONFIG 中提供完整的JSON配置,它会像配置文件一样被解析。

单应用

你也可以单独的定义每一个配置项:

  1. HOST: "0.0.0.0"
  2. PORT: "4040"
  3. MOUNT_PATH: "/"
  4. PARSE_DASHBOARD_TRUST_PROXY: undefined // Or "1" to trust connection info from a proxy's X-Forwarded-* headers
  5. PARSE_DASHBOARD_SERVER_URL: "http://localhost:1337/parse"
  6. PARSE_DASHBOARD_MASTER_KEY: "myMasterKey"
  7. PARSE_DASHBOARD_APP_ID: "myAppId"
  8. PARSE_DASHBOARD_APP_NAME: "MyApp"
  9. PARSE_DASHBOARD_USER_ID: "user1"
  10. PARSE_DASHBOARD_USER_PASSWORD: "pass"
  11. PARSE_DASHBOARD_SSL_KEY: "sslKey"
  12. PARSE_DASHBOARD_SSL_CERT: "sslCert"
  13. PARSE_DASHBOARD_CONFIG: undefined // Only for reference, it must not exist

管理多个应用

在一个仪表盘中管理多个应用也是可以的,只需要在配置项apps数组中增加额外的应用配置即可。

  1. {
  2. "apps": [
  3. {
  4. "serverURL": "https://api.parse.com/1", // Hosted on Parse.com
  5. "appId": "myAppId",
  6. "masterKey": "myMasterKey",
  7. "javascriptKey": "myJavascriptKey",
  8. "restKey": "myRestKey",
  9. "appName": "My Parse.Com App",
  10. "production": true
  11. },
  12. {
  13. "serverURL": "http://localhost:1337/parse", // Self-hosted Parse Server
  14. "appId": "myAppId",
  15. "masterKey": "myMasterKey",
  16. "appName": "My Parse Server App"
  17. }
  18. ]
  19. }

配置应用图标

Parse仪表盘可以为每个应用可选的配置图标,以便你在仪表盘列表中快速识别它们。

你需要在配置项中定义iconsFolder,并且为每个app配置定义iconNameiconsFolder的路径相对配置文件的,如果你的Parse仪表盘是安装在全局的,你需要为iconsFolder指定完整路径。为了直观理解,下面例子中icons的所在位置是和配置文件一样的:

  1. {
  2. "apps": [
  3. {
  4. "serverURL": "http://localhost:1337/parse",
  5. "appId": "myAppId",
  6. "masterKey": "myMasterKey",
  7. "appName": "My Parse Server App",
  8. "iconName": "MyAppIcon.png",
  9. }
  10. ],
  11. "iconsFolder": "icons"
  12. }

作为Express中间件运行

你可以将Parse仪表盘作为Express的中间件运行:

  1. var express = require('express');
  2. var ParseDashboard = require('parse-dashboard');
  3. var dashboard = new ParseDashboard({
  4. "apps": [
  5. {
  6. "serverURL": "http://localhost:1337/parse",
  7. "appId": "myAppId",
  8. "masterKey": "myMasterKey",
  9. "appName": "MyApp"
  10. }
  11. ]
  12. });
  13. var app = express();
  14. // make the Parse Dashboard available at /dashboard
  15. app.use('/dashboard', dashboard);
  16. var httpServer = require('http').createServer(app);
  17. httpServer.listen(4040);

如果你想将ParseServer和Parse仪表盘运行在同一个服务上,可以将他们作为express中间件运行:

  1. var express = require('express');
  2. var ParseServer = require('parse-server').ParseServer;
  3. var ParseDashboard = require('parse-dashboard');
  4. var api = new ParseServer({
  5. // Parse Server settings
  6. });
  7. var options = { allowInsecureHTTP: false };
  8. var dashboard = new ParseDashboard({
  9. // Parse Dashboard settings
  10. }, options);
  11. var app = express();
  12. // make the Parse Server available at /parse
  13. app.use('/parse', api);
  14. // make the Parse Dashboard available at /dashboard
  15. app.use('/dashboard', dashboard);
  16. var httpServer = require('http').createServer(app);
  17. httpServer.listen(4040);

部署仪表盘

安全

为了安全地部署仪表盘,防止你应用的master key泄露,你需要使用HTTPS或基本的身份验证。

部署后的仪表盘会检查你使用的连接是否安全,如果你在负载均衡或前置代理后部署仪表盘,那么仪表盘将不会检查连接是否安全,这种情况下,你可以使用—strstProxy选项来启动仪表盘,以依赖客户端安全连接的头部X-Forwarded-* 。这对于Heroku这样的托管服务很有用,这样你可以信任提供的代理头来判断你使用的是HTTP或HTTPS。你也可以在仪表盘作为express中间件使用的时候设置这个选项。

  1. var trustProxy = true;
  2. var dashboard = new ParseDashboard({
  3. "apps": [
  4. {
  5. "serverURL": "http://localhost:1337/parse",
  6. "appId": "myAppId",
  7. "masterKey": "myMasterKey",
  8. "appName": "MyApp"
  9. }
  10. ],
  11. "trustProxy": 1
  12. });

身份验证

你可以通过添加用户名和密码到配置项中,来为仪表盘添加基本的身份验证:

  1. {
  2. "apps": [{"...": "..."}],
  3. "users": [
  4. {
  5. "user":"user1",
  6. "pass":"pass"
  7. },
  8. {
  9. "user":"user2",
  10. "pass":"pass"
  11. }
  12. ],
  13. "useEncryptedPasswords": true | false
  14. }

你可以将密码明文或bcrypt加密存储,如果是使用bcrypt加密存储,你需要配置useEncryptedPassword参数为true。你可以使用任何bcrypt在线加密工具为你的密码加密,比如:https://www.bcrypt-generator.com。

基于用户的访问权限

如果你为仪表盘配置了多应用管理,你可以基于用户来限制应用的管理。像这样:

  1. {
  2. "apps": [{"...": "..."}],
  3. "users": [
  4. {
  5. "user":"user1",
  6. "pass":"pass1",
  7. "apps": [{"appId": "myAppId1"}, {"appId": "myAppId2"}]
  8. },
  9. {
  10. "user":"user2",
  11. "pass":"pass2",
  12. "apps": [{"appId": "myAppId1"}]
  13. } ]
  14. }

这样配置后,user1可以管理myAppId1和myAppId2,user2只能管理myAppId1。

使用只读masterKey

你可以通过配置readOnlyMasterKey来限制在仪表盘对对象的写操作,readOnlyMasterKey和masterKey很相似,只不过没有写权限。

所用用户使用只读masterKey

在ParseServer中配置如下:

  1. {
  2. "masterKey": "YOUR_MASTER_KEY_HERE",
  3. "readOnlyMasterKey": "YOUR_READ_ONLY_MASTER_KEY",
  4. }

在仪表盘中配置如下:

  1. var trustProxy = true;
  2. var dashboard = new ParseDashboard({
  3. "apps": [
  4. {
  5. "serverURL": "http://localhost:1337/parse",
  6. "appId": "myAppId",
  7. "masterKey": "YOUR_READ_ONLY_MASTER_KEY",
  8. "appName": "MyApp"
  9. }
  10. ],
  11. "trustProxy": 1
  12. });

部分用户使用只读masterKey

使用readOnly将用户标记为只读用户:

  1. {
  2. "apps": [
  3. {
  4. "appId": "myAppId1",
  5. "masterKey": "myMasterKey1",
  6. "readOnlyMasterKey": "myReadOnlyMasterKey1",
  7. "serverURL": "myURL1",
  8. "port": 4040,
  9. "production": true
  10. },
  11. {
  12. "appId": "myAppId2",
  13. "masterKey": "myMasterKey2",
  14. "readOnlyMasterKey": "myReadOnlyMasterKey2",
  15. "serverURL": "myURL2",
  16. "port": 4041,
  17. "production": true
  18. }
  19. ],
  20. "users": [
  21. {
  22. "user":"user1",
  23. "pass":"pass1",
  24. "readOnly": true,
  25. "apps": [{"appId": "myAppId1"}, {"appId": "myAppId2"}]
  26. },
  27. {
  28. "user":"user2",
  29. "pass":"pass2",
  30. "apps": [{"appId": "myAppId1"}]
  31. }
  32. ]
  33. }

user1将只有读操作的权限。

指定应用只读

在每个用户的apps配置项中,你可以基于每个应用的给定只读权限:

  1. {
  2. "apps": [
  3. {
  4. "appId": "myAppId1",
  5. "masterKey": "myMasterKey1",
  6. "readOnlyMasterKey": "myReadOnlyMasterKey1",
  7. "serverURL": "myURL",
  8. "port": 4040,
  9. "production": true
  10. },
  11. {"...": "..."}
  12. ],
  13. "users": [
  14. {
  15. "user":"user",
  16. "pass":"pass",
  17. "apps": [{"appId": "myAppId", "readOnly": true}, {"appId": "myAppId2"}]
  18. }
  19. ]
  20. }

user将会myAppId只有读操作的权限。