资讯专栏INFORMATION COLUMN

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

pcChao / 1784人阅读

摘要:一参考资源网址官网资源站资源站页国内用户文章二开始部署基础环境安装等。安装官网下载安装即可。到安装目的的文件夹运行启动服务。修改结果如下说明是的数据库地址,请确保该地址正确。解决办法是将导入的数据重新导出或,将会获得包含的数据。

一、参考资源网址
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:ForgeMongoDbdb"

$ cd C:Program FilesMongoDBServer3.4in
$ mongod   --dbpath=C:ForgeMongoDbdb

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

 $ "C:Program FilesMongoDBServer3.4inmongod.exe"   --dbpath=C:ForgeMongoDbdb

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:ForgeMongoDbparse-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即可。

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

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/19076.html

相关文章

  • Oracle APEX 系列文章2:在阿里上打造属于你自己的APEX完整开发环境 (准备工作)

    摘要:本系列文章使用的是阿里云的云服务器,仅仅是因为在国内用阿里云的人比较多而已。在这里我们采用将单独部署到上运行的方式完成安装,这也是比较推荐的方式。 本文是钢哥的Oracle APEX系列文章中的其中一篇,完整 Oracle APEX 系列文章如下: Oracle APEX 系列文章1:Oracle APEX, 让你秒变全栈开发的黑科技 Oracle APEX 系列文章2:在阿里云上打...

    MAX_zuo 评论0 收藏0
  • Oracle APEX 系列文章2:在阿里上打造属于你自己的APEX完整开发环境 (准备工作)

    摘要:本系列文章使用的是阿里云的云服务器,仅仅是因为在国内用阿里云的人比较多而已。在这里我们采用将单独部署到上运行的方式完成安装,这也是比较推荐的方式。 本文是钢哥的Oracle APEX系列文章中的其中一篇,完整 Oracle APEX 系列文章如下: Oracle APEX 系列文章1:Oracle APEX, 让你秒变全栈开发的黑科技 Oracle APEX 系列文章2:在阿里云上打...

    xioqua 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<