使用 Parse Server 设置密码重置时出错
Posted
技术标签:
【中文标题】使用 Parse Server 设置密码重置时出错【英文标题】:Error when setting up password reset with Parse Server 【发布时间】:2017-06-19 20:44:56 【问题描述】:我正在使用托管在 Heroku 上的 Parse Server 和 mongoDB。我正在努力使密码重置功能正常工作。我已按照说明将以下代码添加到 index.js。添加此代码后,当应用程序启动或我尝试发送电子邮件时,我收到此错误:JSON text did not start with array or object and option to allow fragments not set.
我知道这意味着服务器无法将数据解析回来,但我完全不确定如何解决这个问题。非常感谢任何帮助!
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var path = require('path');
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 || 'MY_DATABASE_URI',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'MY_APP_ID',
masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'MY_SERVER_URL', // Don't forget to change to https if needed
liveQuery:
classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
verifyUserEmails: true,
//The public URL of your app.
//This will appear in the link that is used to verify email addresses and reset passwords.
//Set the mount path as it is in serverURL
publicServerURL: 'MY_SERVER_URL_FROM_HEROKU',
// Your apps name. This will appear in the subject and body of the emails that are sent.
appName: 'MY_APP_NAME',
// The email adapter
emailAdapter:
module: 'parse-server-simple-mailgun-adapter',
options:
// The address that your emails come from
fromAddress: 'MY_MAILGUN_DOMAIN',
// Your domain from mailgun.com
domain: 'MY_MAILGUN_DOMAIN',
// Your API key from mailgun.com
apiKey: 'MY_API_KEY_FROM_MAILGUN',
);
// 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 = 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);
【问题讨论】:
我认为您需要将此 json 放入 中,但只有此代码脱离上下文。请问,你能放更多的代码吗?例如:var api = new ParseServer... 你也可以使用一些在线工具来验证你的 json.. 感谢@ClaudioCastro。这是我添加的唯一代码。当仅将此代码添加到我的 index.js 文件中时,它会导致应用启动时出错。 我建议显示更多代码,考虑到您无法发现问题并寻求帮助,而那些愿意提供帮助的人说他们需要更多代码。显示完整的应用初始化。 谢谢@JakeT。我非常乐意添加更多代码,只是不确定要添加什么,除非信息上升,否则不想放。正如你所建议的,我已经用整个 index.js 初始化代码更新了这个问题。 【参考方案1】:在设置 verifyUserEmails 之前,livequery:...
之后缺少逗号。由于您为电子邮件添加的块没有正确缩进,所以很难分辨。
【讨论】:
以上是关于使用 Parse Server 设置密码重置时出错的主要内容,如果未能解决你的问题,请参考以下文章
Parse Server - 如何翻译邮件确认页面和密码重置页面
Parse Server 电子邮件中的链接已损坏(验证帐户、重置密码...)
Bitnami EC2 Parse Server Instance,更改默认电子邮件文件
Flutter/dart:Parse Server sdk:ParseUser.currentUser() 函数在重置时返回 null