
parseplatform/parse-serverParse Server 是一个开源后端服务,可部署到任何能运行 Node.js 的基础设施。它提供了与原 Parse 托管服务兼容的 API,支持数据存储、用户认证、云代码(Cloud Code)、实时查询(Live Query)和 GraphQL 等功能,适用于快速构建移动应用、Web 应用的后端服务,或作为原 Parse 服务的替代方案。
!Parse Server
| 版本 | 最新版本 | 生命周期结束日期 | 兼容性 |
|---|---|---|---|
| Node.js 12 | 12.22.3 | 2022年4月 | ✅ 完全兼容 |
| Node.js 14 | 14.17.3 | 2023年4月 | ✅ 完全兼容 |
| Node.js 15 | 15.14.0 | 2021年6月 | ✅ 完全兼容 |
| 版本 | 最新版本 | 生命周期结束日期 | 兼容性 |
|---|---|---|---|
| MongoDB 4.0 | 4.0.25 | 2022年4月 | ✅ 完全兼容 |
| MongoDB 4.2 | 4.2.15 | 待定 | ✅ 完全兼容 |
| MongoDB 4.4 | 4.4.7 | 待定 | ✅ 完全兼容 |
| MongoDB 5.0 | 5.0.1 | 2024年1月 | ✅ 完全兼容 |
| 版本 | PostGIS 版本 | 生命周期结束日期 | Parse Server 支持结束 | 兼容性 |
|---|---|---|---|---|
| Postgres 11 | 3.0, 3.1 | 2023年11月 | 2022年4月 | ✅ 完全兼容 |
| Postgres 12 | 3.1 | 2024年11月 | 2023年4月 | ✅ 完全兼容 |
| Postgres 13 | 3.1 | 2025年11月 | 2024年4月 | ✅ 完全兼容 |
安装依赖:
bashnpm install -g parse-server mongodb-runner
启动 MongoDB:
bashmongodb-runner start
启动 Parse Server:
bashparse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://localhost/test
注意:如果全局安装(
-g)因权限问题失败(npm ERR! code 'EACCES'),请参考 npm 权限修复指南。
bash# 拉取 Parse Server 代码 git clone [***] cd parse-server # 构建 Docker 镜像 docker build --tag parse-server . # 启动 MongoDB 容器 docker run --name my-mongo -d mongo
bashdocker run --name my-parse-server \ -v config-vol:/parse-server/config \ -p 1337:1337 \ --link my-mongo:mongo \ -d parse-server \ --appId APPLICATION_ID \ --masterKey MASTER_KEY \ --databaseURI mongodb://mongo/test
使用云代码:如需启用云代码,添加
-v cloud-code-vol:/parse-server/cloud --cloud /parse-server/cloud/main.js参数(确保main.js位于cloud-code-vol目录中)。
使用 REST API 保存对象:
bashcurl -X POST \ -H "X-Parse-Application-Id: APPLICATION_ID" \ -H "Content-Type: application/json" \ -d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' \ http://localhost:1337/parse/classes/GameScore
响应示例:
json{ "objectId": "2ntvSpRGIK", "createdAt": "2016-03-11T23:51:48.050Z" }
查询对象:
bashcurl -X GET \ -H "X-Parse-Application-Id: APPLICATION_ID" \ http://localhost:1337/parse/classes/GameScore
Parse 提供各主流平台的 SDK(iOS、Android、JavaScript 等),配置 SDK 连接 Parse Server 时需指定 serverURL,例如:
javascript// JavaScript SDK 示例 Parse.initialize("APPLICATION_ID"); Parse.serverURL = "http://localhost:1337/parse";
| 参数名 | 说明 | 是否必填 |
|---|---|---|
appId | 应用 ID,可自定义字符串,迁移应用需与原 Parse 应用 ID 一致 | ✅ 是 |
masterKey | 主密钥,用于覆盖 ACL 安全控制,需保密,迁移应用需与原 Parse 主密钥一致 | ✅ 是 |
databaseURI | 数据库连接字符串,如 mongodb://user:***/dbname | ✅ 是 |
port | 服务端口,默认 1337 | ❌ 否 |
serverURL | Parse Server 访问 URL(如 http://localhost:1337/parse) | ❌ 否 |
cloud | 云代码入口文件路径(如 ./cloud/main.js) | ❌ 否 |
push | 推送通知配置(APNS/GCM) | ❌ 否 |
如需要求客户端提供密钥,可配置以下参数(设置后所有请求需包含对应密钥):
clientKeyjavascriptKeyrestAPIKeydotNetKey需配置邮件适配器实现***验证和密码重置功能,示例配置:
javascriptconst server = ParseServer({ ...otherOptions, verifyUserEmails: true, // 启用***验证 emailVerifyTokenValidityDuration: 2 * 60 * 60, // 验证令牌有效期 2 小时 emailAdapter: { module: 'parse-server-sendgrid-adapter', // 示例:SendGrid 适配器 options: { apiKey: 'SENDGRID_API_KEY', fromAddress: '***' } } });
常用邮件适配器:
配置账户安全策略示例:
javascriptconst server = ParseServer({ ...otherOptions, accountLockout: { duration: 5, // 账户锁定 5 分钟 threshold: 3, // 3 次登录失败后锁定 unlockOnPasswordReset: true // 密码重置后解锁 }, passwordPolicy: { validatorPattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.{8,})$/, // 8位以上,含大小写字母和数字 doNotAllowUsername: true, // 密码不可包含用户名 maxPasswordHistory: 5 // 禁止重用最近 5 次密码 } });
通过 pages 配置添加自定义路由,示例:
javascriptconst api = new ParseServer({ ...otherOptions, pages: { enableRouter: true, // 启用自定义路由(实验性) customRoutes: [{ method: 'GET', path: 'custom_route', handler: async request => { // 自定义逻辑 return { file: 'custom_page.html' }; // 返回 HTML 文件 } }] } });
访问路径:https://[parseServerPublicUrl]/[parseMount]/[pagesEndpoint]/[appId]/custom_route
保留路径:
verify_email、resend_verification_email、choose_password、request_password_reset为系统内置路径,不可自定义。
所有配置选项可通过环境变量设置,例如:
PARSE_SERVER_APP_ID:对应 appIdPARSE_SERVER_MASTER_KEY:对应 masterKeyPARSE_SERVER_DATABASE_URI:对应 databaseURIyamlversion: '3' services: mongo: image: mongo container_name: my-mongo restart: always volumes: - mongo-data:/data/db parse-server: build: . container_name: my-parse-server restart: always ports: - "1337:1337" volumes: - config-vol:/parse-server/config - cloud-code-vol:/parse-server/cloud environment: - PARSE_SERVER_APP_ID=APPLICATION_ID - PARSE_SERVER_MASTER_KEY=MASTER_KEY - PARSE_SERVER_DATABASE_URI=mongodb://mongo/test - PARSE_SERVER_CLOUD=/parse-server/cloud/main.js depends_on: - mongo volumes: mongo-data: config-vol: cloud-code-vol:

manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务