赶在关闭前,Parse Server Migration总结

2015年开始使用Parse Server,用作自己开发的iOS应用的后台,可是刚开发了两个APP,Parse Server就宣布停止服务了,截止日期是2017年1月28日。

随着这个日子越来越逼近,自己也一直在纠结怎么处理这两个应用。停止服务?迁移到LeanCloud?还是自己搭建Parse Server来维护?

中间纠结过也探索过,尤其想迁移到LeanCloud,因为自己对服务器端开发的了解几乎等于零。但随着LeanCloud收费的改变,和迁移到LeanCloud时遇到的种种坑。最终决定自己来搭建Parse Server,顺带也学习一点服务器端开发相关的知识吧。

首先是云服务器和域名的购买,现在产品非常多,国外的AWS,微软等,国内有阿里云,百度云,腾讯云等等。在拿到腾讯云的7天试用之后,觉得基本满意,所以就继续用腾讯云了,顺带注册了域名。整个过程非常简单,不像以前那么麻烦了。

开始迁移
Parse官方给出的迁移步骤:Migrating an Existing Parse App
Parse官方的Github:parse-server

个人感觉迁移的内容写的比较粗略,而且东西比较散乱,可能是我对服务器开发不熟悉的缘故吧。

最终指引我安装的主要是下面几篇文章,都不是官方的。(残念)
How To Run Parse Server On Ubuntu 14.04
How To Migrate a Parse App to Parse Server on Ubuntu 14.04

通过上面的两篇,基本搞定了Parse Server最基本的配置,启动和运行,同时把我在Parse.com的其中一个应用的数据迁移到了自己的服务器。

然后配置DashBoard
How to setup parse-dashboard alongside parse-server on Digital Ocean

如果你搞定了这一步,那么恭喜你,基本上70%的工作都完成了。

剩下的问题:
第一个问题就是图片问题,迁移的时候并没有把图片文件迁移过来,所以一旦Parse.com服务中断,所有的图片就无法访问了。因此还需要把图片迁移到自己的服务器中。

所以需要做的事是:

  1. 在自己的服务器中,为Parse Server配置File Server Adapter
    看这边的介绍 [parse-server-fs-adapter] (https://github.com/parse-server-modules/parse-server-fs-adapter)

  2. parse-files-utils这个工具把图片文件从Parse.com下载下来,并放置到上面配置的那个文件目录中去。

Push问题:
Push Overview
Push Configuring Clients
Push相对来说比较简单了,服务器端配置下.p12文件,修改下客户端就可以了。

最后给出我的index.js文件供大家参考

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Packtor Server
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var ParseDashboard = require('parse-dashboard');
var path = require('path');
var FSFilesAdapter = require('parse-server-fs-adapter');

var fsAdapter = new FSFilesAdapter({
"filesSubDirectory": "learnpaint/files"
});

var databaseUri = process.env.DATABASE_URI || 'mongodb://dbuser:password@your_domain:27017/your_dbname?ssl=true';

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

// Set up parse server
var api = new ParseServer({
databaseURI: databaseUri,
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'your_app_id',
masterKey: process.env.MASTER_KEY || 'your_app_master_key',
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse',
publicServerURL: 'https://your_domain/parse',
filesAdapter: fsAdapter,
push: {
ios: [
{
pfx: '/home/parse/files/xxxxxxx.p12', // The filename of private key and certificate in PFX or PKCS12 f$
passphrase: '', // optional password to your p12
bundleId: 'your_boundle_id', // The bundle identifier associate with your app
production: false // Specifies which environment to connect to: Production (if true) or Sandbox
},
{
pfx: '/home/parse/files/xxxxxxx.p12', // The filename of private key and certificate in PFX or PKCS12 fo$
passphrase: '', // optional password to your p12
bundleId: 'your_boundle_id', // The bundle identifier associate with your app
production: true // Specifies which environment to connect to: Production (if true) or Sandbox
}
]
}
});