parse-server和parse-dashboard安装及阿里云express部署

一、参考资源网址
1、http://parseplatform.org/#server 官网
2、https://github.com/parse-comm… github资源站
3、https://github.com/parse-comm… github资源站
4、http://docs.parseplatform.org… parse-server guide页
5、http://www.shirlman.com/tec/2… 国内用户文章

二、开始部署
1、基础环境:安装git nodejs express 等。
2、安装MongoDB:官网下载安装即可。
3、启动MongoDB:启动cmd,运行下面命令。
(1) cd到安装目的的bin文件夹 C:Program FilesMongoDBServer3.4bin
(2) 运行mongod 启动服务。–dbpath为数据库路径,需要事先创建路径'C:\Forge\MongoDb\db'

$ cd C:\Program Files\MongoDB\Server\3.4\bin
$ mongod   --dbpath=C:\Forge\MongoDb\db

注:启动服务也可以直接在cmd中执行下面命令:

 $ "C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe"   --dbpath=C:\Forge\MongoDb\db

4、安装parser-server:

  $ npm install -g parse-server mongodb-runner

5、安装Parse-Dashboard

$ npm install -g parse-dashboard

至此,parse-server和dashboard都已经安装好了,接下来就是如何进行配置和在express中启动服务了。

三、参数配置及利用express启动parse-server和dashboard服务
1、安装parse-server启动样例,可以从github中下载并在本地解压:https://github.com/parse-comm…
2、修改index.js文件parse-server-example中只包含了parse-server服务,需要同时启动dashboard服务就需要修改index.js文件。修改结果如下:

// Example express application adding the parse-server module to expose Parse
// compatible API routes.

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var path = require('path');

var allowInsecureHTTP = true;
var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;

if (!databaseUri) {
  console.log('DATABASE_URI not specified, falling back to localhost.');
}

var api = new ParseServer({
  databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || 'myAppId',
  masterKey: process.env.MASTER_KEY || 'myMasterKey', //Add your master key here. Keep it secret!
  serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse',  // Don't forget to change to https if needed
  liveQuery: {
    classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
  }
});
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
// If you wish you require them, you can set them as options in the initialization above:
// javascriptKey, restAPIKey, dotNetKey, clientKey

var app = express();

// Serve static assets from the /public folder
app.use('/public', express.static(path.join(__dirname, '/public')));

// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);

// Parse Server plays nicely with the rest of your web routes
app.get('/', function(req, res) {
  res.status(200).send('I dream of being a website.  Please star the parse-server repo on GitHub!');
});

// There will be a test page available on the /test path of your server url
// Remove this before launching your app
app.get('/test', function(req, res) {
  res.sendFile(path.join(__dirname, '/public/test.html'));
});

var port =  1337;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
    console.log('parse-server-example running on port ' + port + '.');
});

// This will enable the Live Query real-time server
ParseServer.createLiveQueryServer(httpServer);

var ParseDashboard = require('parse-dashboard');

var dashboard = new ParseDashboard({
  apps: [
    {
      appId: process.env.APP_ID || 'myAppId',
      masterKey:  'myMasterKey',
      serverURL:  'http://your_ip_address:1337/parse',
      appName: process.env.APP_NAME || 'MyApp'
    }
  ],
  users: 
  [
    {
        user:"admin",
        pass:"admin"
    }
  ]
},allowInsecureHTTP);
// make the Parse Dashboard available at /
app.use('/dash', dashboard);

var port2 =  4040;
var httpServer = require('http').createServer(app);
httpServer.listen(port2, function() {
  console.log('parse-dashboard-example running on port ' + port2 + '.');
});

说明:
(1)、databaseURI: databaseUri || ‘mongodb://localhost:27017/dev’,
databaseURI是mongoDB的数据库地址,请确保该地址正确。
(2)、参数allowInsecureHTTP 是为了保证远程能够访问。
(3)、出现错误提示Configure a user to access Parse Dashboard remotely说明没有配置访问用户,需要在ParseDashboard中增加下面用户配置。

  users: 
  [
    {
        user:"admin",
        pass:"admin"
    }
  ]

(4)登录面板中app无法操作,提示:Server not reachable: unauthorized,这是因为在dashboard配置中需要把localhost改成你的公网ip,如下
serverURL: ‘http://your_ip_address:1337/p…‘,
3、cd 到parse-server-example目录

$ cd C:\Forge\MongoDb\parse-server-example-master

4、cmd中输入如下命令启动parse-server和parse-dashboard

   $ npm start

5、访问localhost:4040/dash 即可进入parse面板 (用户名;admin 密码:admin)

四、mongoDB数据管理

1、mongochef:https://studio3t.com/download/ 页面中选择4.5.5 版本:
3T Mongo Chef Core即可免费使用。其他高版本好像要收费使用。
2、mongochef 可以远程访问mongoDB数据,可以导入、导出数据。导入数据的时候会发现dashboard中没有变化,这是因为还需要手工维护_SCHEMA表数据。
3、mongochef导入数据,发现无法修改,提示object not exist,这是因为导入数据时自动生成的_id的格式是objectID。parser的格式是string,所以导致parse的无法获得其objectID。解决办法是:将导入的数据重新导出csv或json,将会获得包含——id的数据。将数据重新导入,导入的时候在下面选择_id格式为String即可。
《parse-server和parse-dashboard安装及阿里云express部署》

至此,就可以通过postman 尽情测试了。测试可以参考restAPI:http://docs.parseplatform.org…

    原文作者:吴礼财
    原文地址: https://segmentfault.com/a/1190000010927322
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞