抛出“你必须提供一个 appId 和主密钥!”;

throw 'You must provide an appId and masterKey!';

本文关键字:appId 一个 主密钥 抛出      更新时间:2023-09-26

我正在从解析中迁移我的应用程序并经历parse-migration guide

我在 https://github.com/ParsePlatform/parse-server-example 本地执行了解析服务器示例,它工作正常,但之后我尝试从 https://github.com/ParsePlatform/parse-server 运行解析服务器,但错误显示为

throw 'You must provide an appId and masterKey!'; 

在命令提示符下。

在索引中添加了 mongodb url 和其他键.js 和数据适配器.js但我不知道在哪里为主密钥和应用程序 ID 添加值。

你永远不必从github手动下载parse-server。大多数情况下,这是由 npm 处理的。您提到的parse-server-example已经使用 parse-server 来启动并运行基本应用程序。 parse-server-example是构建自己的应用程序的良好起点,您永远不必"切换"到其他应用程序。

看到的错误是因为您没有在解析配置中提供 appId 和主密钥。这是从parse-server-example复制的,是配置对象的样子。

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 || '', //Add your master key here. Keep it secret!
  serverURL: process.env.SERVER_URL || 'http://localhost:1337'  // Don't forget to change to https if needed
});

Parse Server 只是另一个 npm 模块,所以我建议在使用之前先阅读 nodejs 和 npm。

我不确定这是最好的解决方案,但在提示符中尝试一下:

export API_KEY=foo
export MASTER_KEY=bar

(当然,只需将foobar替换为您自己的密钥即可。
然后,再次npm start,它将正常工作。