0

在 Parse-Server (/Heroku) 上创建帐户时,我遇到的问题与电子邮件验证有关的问题比我想的要长。尽管我在这个问题上发表了一些帖子,但我并没有足够幸运(或者可能没有足够清楚地表述事情)来获得重要的帮助。所以我决定重新做一遍,这一次给出了一个精确的逐步重现错误的方法,任何有兴趣仔细观察的人。如果我所做的从头到尾都是正确的,那么一定有一个错误。另一方面,如果我做错了什么(很可能是这种情况),我希望有人能指出错误。

这是过程,首先在 heroku 上创建一个应用程序,在终端上使用以下命令:

git clone https://github.com/parse-community/parse-server-example.git
mv parse-server-example linkbugapp808
cd linkbugapp808/
npm install @parse/simple-mailgun-adapter  --save
heroku create linkbugapp808

heroku addons:create mongolab:sandbox
heroku config:set APP_ID=ABCDEF-12345678:xytzt_SSTTJJZ
heroku config:set MASTER_KEY=MMMMM-87878787:wwyyssaa_PPGHYU
heroku config:set SERVER_URL=https://linkbugapp808.herokuapp.com/
heroku config:set PARSE_PUBLIC_SERVER_URL=https://linkbugapp808.herokuapp.com

当然,如果我使用的名称“linkbugapp808”被占用或者您不喜欢它,您可以选择另一个。

将 index.js 文件设置为这样(修复需要修复的 mailgun 参数,以适应您的环境):

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

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,
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID,
  masterKey: process.env.MASTER_KEY,
  serverURL: process.env.SERVER_URL,
  publicServerURL: process.env.PARSE_PUBLIC_SERVER_URL,
  appName: 'LinkBugApp',
  verifyUserEmails: true,
  emailAdapter: {
    module: '@parse/simple-mailgun-adapter',
    options: {
      fromAddress: 'from@somemail.com',
      domain: 'some.domain',
      apiKey: 'key-apiKey-mailgun-apiKey'
    }
  }
});

var app = express();

// Serve static assets from the /public folder
app.use('/public', express.static(path.join(__dirname, '/public')));
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');

// 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 = process.env.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);

接下来在终端中运行以下命令(在 linkbugapp808 根文件夹内):

git add . && git commit -m "update linkbugapp808" && git push heroku master

此时,应用程序已在 Heroku 上创建并准备就绪。

然后从一个 iOS 应用程序在我们上面设置的 Parse-Server 上创建一个帐户。

一切似乎都很好。

为其创建帐户的用户将收到与此类似的邮件:

Hi,

You are being asked to confirm the e-mail address usermail@xmail.com with LinkBugApp

Click here to confirm it:
https://linkbugapp808.herokuapp.com/apps/ABCDEF-12345678:xytzt_SSTTJJZ/verify_email?token=SiYyk9NgVkcwhXXWlEdEUTjyz&username=ausrnamex

当点击邮件内的确认链接时,这是可以看到的(与注册确认链接所期望的不完全一样):

Cannot GET /apps/ABCDEF-12345678:xytzt_SSTTJJZ/verify_email?token=SiYyk9NgVkcwhXXWlEdEUTjyz&username=ausrnamex 

我尝试了几种浏览器,但结果是相同的。

为什么我们会陷入这种境地?

4

0 回答 0