



解析服务器是一种开源后端,可以部署到可以运行Node.js的任何基础架构中。解析服务器可与Express Web应用程序框架一起使用。它可以添加到现有的Web应用程序中,也可以单独运行。
Wiki中提供了解析服务器的完整文档。解析服务器指南是入门的好地方。 API参考和云代码指南也可用。如果您有兴趣开发Parse Server,则开发指南将帮助您设置。
非常感谢我们支持解析平台开发的赞助商和支持者!
解析服务器有不同分支的不同口味可用:
release-<version>.xx ,例如release-5.xx 。 LTS分支没有预释放分支。 为以前的解析服务器专业版本提供了长期支持(LTS)。例如,Parse Server 5.X将接收安全更新,直到解析服务器6.x被解析服务器7.x取代并成为新的LTS版本。当当前的主要版本发布在分支release上时,LTS版本发表在分支release-#.xx上,例如Parse Server 5.x LTS分支的release-5.xx 。
最快,最简单的入门方法是在本地运行MongoDB和解析服务器。
在开始之前,请确保已安装:
npm的nodejs对node.js的最新版本对解析服务器进行了连续测试,以确保兼容性。我们遵循Node.js的长期支持计划,仅针对正式支持且未达到其寿命终止日期的版本进行测试。
| 版本 | 最新版本 | 寿命 | 兼容的 |
|---|---|---|---|
| Node.js 18 | 18.20.4 | 2025年4月 | ✅是的 |
| Node.js 20 | 20.15.1 | 2026年4月 | ✅是的 |
| Node.js 22 | 22.4.1 | 2027年4月 | ✅是的 |
对MongoDB的最新发行版进行了对解析服务器的持续测试,以确保兼容性。我们遵循MongoDB的支持时间表和MongoDB生命周期时间表,仅针对正式支持且未达到其寿命终止日期的版本进行测试。 MongoDB“快速发行”被忽略,因为这些被认为是下一个主要版本的预释放。
| 版本 | 最新版本 | 寿命 | 兼容的 |
|---|---|---|---|
| MongoDB 4.2 | 4.2.25 | 2023年4月 | ✅是的 |
| MongoDB 4.4 | 4.4.29 | 2024年2月 | ✅是的 |
| Mongodb 5 | 5.0.26 | 2024年10月 | ✅是的 |
| Mongodb 6 | 6.0.14 | 2025年7月 | ✅是的 |
| Mongodb 7 | 7.0.8 | TDB | ✅是的 |
| Mongodb 8 | 8.0.0 | TDB | ✅是的 |
使用PostGIS Docker Images,对PostgreSQL和PostGIS的最新发行版进行了对Parse Server的持续测试,以确保兼容性。我们遵循PostgreSQL支持时间表和后GIS支持时间表,仅针对官方支持且未达到其寿命日期的版本进行测试。由于大量的PostgreSQL支持持续时间为5年,Parse Server在正式终止日期之前大约2年下降了支持。
| 版本 | PostGIS版本 | 寿命 | 解析服务器支持 | 兼容的 |
|---|---|---|---|---|
| Postgres 13 | 3.1、3.2、3.3、3.4、3.5 | 2025年11月 | <= 6.x(2023) | ✅是的 |
| Postgres 14 | 3.5 | 2026年11月 | <= 7.x(2024) | ✅是的 |
| Postgres 15 | 3.5 | 2027年11月 | <= 8.x(2025) | ✅是的 |
| Postgres 16 | 3.5 | 2028年11月 | <= 9.x(2026) | ✅是的 |
| Postgres 17 | 3.5 | 2029年11月 | <= 9.x(2026) | ✅是的 |
$ npm install -g parse-server mongodb-runner
$ mongodb-runner start
$ parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://localhost/test注意:如果由于权限问题( npm ERR! code 'EACCES' )而使用-g安装失败,请参阅此链接。
$ git clone https://github.com/parse-community/parse-server
$ cd parse-server
$ docker build --tag parse-server .
$ docker run --name my-mongo -d mongo$ docker 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目录中。
您可以将任何任意字符串用作应用程序ID和主密钥。您的客户将使用这些用来使用Parse服务器进行身份验证。
就是这样!现在,您正在计算机上运行独立版本的Parse服务器。
使用远程mongodb?启动parse-server时,传递--databaseURI DATABASE_URI参数。在此处了解有关配置Parse服务器的更多信息。有关可用选项的完整列表,请运行parse-server --help 。
现在您正在运行解析服务器,现在该保存第一个对象了。我们将使用REST API,但是您可以使用任何Parse SDK轻松地执行相同的操作。运行以下内容:
$ curl -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您应该得到类似的答复:
{
"objectId" : "2ntvSpRGIK" ,
"createdAt" : "2016-03-11T23:51:48.050Z"
}现在,您可以直接检索此对象(确保用创建对象时收到的实际objectId替换2ntvSpRGIK ):
$ curl -X GET
-H " X-Parse-Application-Id: APPLICATION_ID "
http://localhost:1337/parse/classes/GameScore/2ntvSpRGIK // Response
{
"objectId" : " 2ntvSpRGIK " ,
"score" : 1337 ,
"playerName" : " Sean Plott " ,
"cheatMode" : false ,
"updatedAt" : " 2016-03-11T23:51:48.050Z " ,
"createdAt" : " 2016-03-11T23:51:48.050Z "
}但是,跟踪单个对象ID并不理想。在大多数情况下,您将需要在集合上运行查询,例如:
$ curl -X GET
-H " X-Parse-Application-Id: APPLICATION_ID "
http://localhost:1337/parse/classes/GameScore // The response will provide all the matching objects within the `results` array:
{
"results" : [
{
"objectId" : " 2ntvSpRGIK " ,
"score" : 1337 ,
"playerName" : " Sean Plott " ,
"cheatMode" : false ,
"updatedAt" : " 2016-03-11T23:51:48.050Z " ,
"createdAt" : " 2016-03-11T23:51:48.050Z "
}
]
}要了解有关在解析服务器上使用保存和查询对象的更多信息,请查看解析文档。
Parse为所有主要平台提供了SDK。请参阅《解析服务器指南》,以了解如何将应用程序连接到解析服务器。
一旦您对项目的工作原理有了更好的了解,请参阅Parse Server Wiki,以便深入指南将解析服务器部署到主要的基础架构提供商。继续阅读以了解更多有关运行解析服务器的其他方法。
我们提供了一个基本的Node.js应用程序,该应用程序使用Express上的Parse Server模块,并且可以轻松地部署到各种基础架构提供商:
您还可以创建解析服务器的实例,并将其安装在新的或现有的Express网站上:
const express = require ( 'express' ) ;
const ParseServer = require ( 'parse-server' ) . ParseServer ;
const app = express ( ) ;
const server = new ParseServer ( {
databaseURI : 'mongodb://localhost:27017/dev' , // Connection string for your MongoDB database
cloud : './cloud/main.js' , // Path to your Cloud Code
appId : 'myAppId' ,
masterKey : 'myMasterKey' , // Keep this key secret!
fileKey : 'optionalFileKey' ,
serverURL : 'http://localhost:1337/parse' // Don't forget to change to https if needed
} ) ;
// Start server
await server . start ( ) ;
// Serve the Parse API on the /parse URL prefix
app . use ( '/parse' , server . app ) ;
app . listen ( 1337 , function ( ) {
console . log ( 'parse-server-example running on port 1337.' ) ;
} ) ;有关可用选项的完整列表,请运行parse-server --help或查看[Parse Server配置] [Server-Options]。
通过向/parse/health端点发送请求来检查解析服务器健康。
响应看起来像这样:
{
"status" : " ok "
}| 价值 | 描述 |
|---|---|
initialized | 已经创建了服务器,但尚未调用start方法。 |
starting | 服务器正在启动。 |
ok | 服务器启动并正在运行。 |
error | 有一个启动错误,有关详细信息,请参见日志。 |
可以使用以下选项配置解析服务器。运行独立parse-server时,您可以将它们作为参数传递,或使用parse-server path/to/configuration.json加载以JSON格式加载配置文件。如果您在Express上使用Parse Server,则也可以将其传递给ParseServer对象作为选项。
有关可用选项的完整列表,请运行parse-server --help或查看[Parse Server配置] [Server-Options]。
appId (必需) - 使用此服务器实例托管的应用ID。您可以使用任何任意字符串。对于迁移的应用程序,这应该与您的托管解析应用程序匹配。masterKey (必需) - 用于覆盖ACL安全性的主密钥。您可以使用任何任意字符串。保密!对于迁移的应用程序,这应该与您的托管解析应用程序匹配。databaseURI (必需) - 数据库的连接字符串,即mongodb://user:[email protected]/dbname 。如果您的密码具有特殊字符,请确保编码密码。port - 默认端口为1337,指定此参数以使用其他端口。serverURL解析服务器的URL(不要忘记指定http://或https://)。从云代码提出请求解析服务器时,将使用此URL。cloud - 云代码main.js文件的绝对路径。push - APN和GCM推送的配置选项。请参阅快速启动推送通知。 对于解析服务器,不再需要与Parse一起使用的客户端密钥。如果您希望仍然需要它们,也许可以拒绝访问老年客户端,则可以在初始化时设置钥匙。设置这些密钥中的任何一个都需要所有请求以提供一个配置的密钥之一。
clientKeyjavascriptKeyrestAPIKeydotNetKey| 范围 | 内部数据 | 只读数据(1) | 自定义数据 | 受CLP限制,ACL | 钥匙 |
|---|---|---|---|---|---|
| 内部的 | r/w | r/w | r/w | 不 | maintenanceKey |
| 掌握 | - / - | r/ - | r/w | 不 | masterKey |
| Readonlymaster | - / - | r/ - | r/ - | 不 | readOnlyMasterKey |
| 会议 | - / - | r/ - | r/w | 是的 | sessionToken |
(1) Parse.Object.createdAt , Parse.Object.updatedAt 。
验证用户电子邮件地址并通过电子邮件重置密码需要电子邮件适配器。社区提供和维护许多电子邮件适配器。以下是带有示例电子邮件适配器的示例配置。有关更多详细信息,请参见[Parse Server选项] [Server-Options],以及可用选项的完整列表。
const server = ParseServer ( {
... otherOptions ,
// Enable email verification
verifyUserEmails : true ,
// Set email verification token validity to 2 hours
emailVerifyTokenValidityDuration : 2 * 60 * 60 ,
// Set email adapter
emailAdapter : {
module : 'example-mail-adapter' ,
options : {
// Additional adapter options
... mailAdapterOptions
}
} ,
} ) ;Parse平台维护的官方电子邮件适配器:
社区贡献的电子邮件适配器:
设置满足您安全要求的密码和帐户策略。以下是示例配置。有关更多详细信息,请参见[Parse Server选项] [Server-Options],以及可用选项的完整列表。
const server = ParseServer ( {
... otherOptions ,
// The account lock policy
accountLockout : {
// Lock the account for 5 minutes.
duration : 5 ,
// Lock an account after 3 failed log-in attempts
threshold : 3 ,
// Unlock the account after a successful password reset
unlockOnPasswordReset : true ,
} ,
// The password policy
passwordPolicy : {
// Enforce a password of at least 8 characters which contain at least 1 lower case, 1 upper case and 1 digit
validatorPattern : / ^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.{8,}) / ,
// Do not allow the username as part of the password
doNotAllowUsername : true ,
// Do not allow to re-use the last 5 passwords when setting a new password
maxPasswordHistory : 5 ,
} ,
} ) ; 谨慎,这是一个实验特征,可能不适合生产。
自定义路线允许使用网页构建用户流,类似于现有密码重置和电子邮件验证功能。自定义路由在Parse服务器配置中使用pages选项定义:
const api = new ParseServer ( {
... otherOptions ,
pages : {
enableRouter : true , // Enables the experimental feature; required for custom routes
customRoutes : [ {
method : 'GET' ,
path : 'custom_route' ,
handler : async request => {
// custom logic
// ...
// then, depending on the outcome, return a HTML file as response
return { file : 'custom_page.html' } ;
}
} ]
}
}可以通过向以下方式发送GET请求来调用上述路由: https://[parseServerPublicUrl]/[parseMount]/[pagesEndpoint]/[appId]/[customRoute]
handler接收request ,并从pages.pagesPath返回custom_page.html网页。以这种方式构建自定义路线的优点是,它会自动利用Parse Server的内置功能,例如页面本地化和动态占位符。
Parse Server的内置功能已经使用以下路径,因此无法用于自定义路由。具有相同path和method组合的自定义路线被忽略。
| 小路 | HTTP方法 | 特征 |
|---|---|---|
verify_email | GET | 电子邮件验证 |
resend_verification_email | POST | 电子邮件验证 |
choose_password | GET | 密码重置 |
request_password_reset | GET | 密码重置 |
request_password_reset | POST | 密码重置 |
| 范围 | 选修的 | 类型 | 默认值 | 示例值 | 环境变量 | 描述 |
|---|---|---|---|---|---|---|
pages | 是的 | Object | undefined | - | PARSE_SERVER_PAGES | 诸如密码重置和电子邮件验证等页面的选项。 |
pages.enableRouter | 是的 | Boolean | false | - | PARSE_SERVER_PAGES_ENABLE_ROUTER | 如果应启用页面路由器,则为true ;任何页面选项都需要生效所必需的。谨慎,这是一个实验特征,可能不适合生产。 |
pages.customRoutes | 是的 | Array | [] | - | PARSE_SERVER_PAGES_CUSTOM_ROUTES | 自定义路线。这些路线是按照此处定义的顺序添加的,必须考虑该路线,因为请求以有序的方式横穿路线。自定义路线在建立路线(例如密码重置和电子邮件验证)之后进行穿越。 |
pages.customRoutes.method | String | - | GET , POST | - | 自定义路线的HTTP方法。 | |
pages.customRoutes.path | String | - | custom_page | - | 自定义路线的路径。请注意,如果该method不同,可以使用相同的路径,例如,路径custom_page可以具有两个路由,即GET和POST路由,该路由将根据HTTP请求方法调用。 | |
pages.customRoutes.handler | AsyncFunction | - | async () => { ... } | - | 路由与HTTP请求匹配时被调用的路由处理程序。如果处理程序未返回页面,则将请求回答404 Not found.回复。 |
可以更改应用程序的默认页面,并将用户重定向到另一个路径或域。
const server = ParseServer ( {
... otherOptions ,
customPages : {
passwordResetSuccess : "http://yourapp.com/passwordResetSuccess" ,
verifyEmailSuccess : "http://yourapp.com/verifyEmailSuccess" ,
parseFrameURL : "http://yourapp.com/parseFrameURL" ,
linkSendSuccess : "http://yourapp.com/linkSendSuccess" ,
linkSendFail : "http://yourapp.com/linkSendFail" ,
invalidLink : "http://yourapp.com/invalidLink" ,
invalidVerificationLink : "http://yourapp.com/invalidVerificationLink" ,
choosePassword : "http://yourapp.com/choosePassword"
}
} ) 您可以使用环境变量配置解析服务器:
PORT
PARSE_SERVER_APPLICATION_ID
PARSE_SERVER_MASTER_KEY
PARSE_SERVER_DATABASE_URI
PARSE_SERVER_URL
PARSE_SERVER_CLOUD默认端口为1337,使用其他端口设置端口环境变量:
$ PORT=8080 parse-server --appId APPLICATION_ID --masterKey MASTER_KEY有关可配置环境变量的完整列表,请运行parse-server --help或查看Parse服务器配置。
所有官方适配器均以NPM(@parse)的范围范围的范围分发。
Parse Server模块组织中还提供了一些维护良好的适配器。
您还可以通过在NPM上搜索社区维护的更多适配器。
解析服务器允许开发人员在托管文件时从几个选项中进行选择:
GridFSBucketAdapter由MongoDB支持S3Adapter由亚马逊S3支持GCSAdapter由Google Cloud Storage支持FSAdapter本地文件存储默认情况下使用GridFSBucketAdapter ,不需要设置,但是如果您有兴趣使用Amazon S3,Google Cloud Storage或本地文件存储,则可以在“ Parse Server指南”中获得其他配置信息。
谨慎,这是一个实验特征,可能不适合生产。
此功能将重复数据删除由Parse Server多次收到的相同请求,通常是由于网络问题或移动操作系统上的网络适配器访问限制。
相同的请求由其请求标题X-Parse-Request-Id确定。因此,客户请求必须包括此标头以进行重复数据删除。不包含此标头的请求不能被重复地重复解复,并且通过Parse Server正常处理。这意味着向客户端推出此功能是无缝的,因为启用此功能时,解析服务器仍在没有此标头的情况下处理请求。
需要在客户端启用此功能以发送标头和服务器以处理标题。请参阅特定的Parse SDK文档,以查看是否支持该功能。
重复数据删除仅用于对象创建和更新( POST和PUT请求)。对于对象查找和删除( GET和DELETE请求),重复数据删除尚未进行,因为根据定义,这些操作已经存在。
let api = new ParseServer({
idempotencyOptions: {
paths: [".*"], // enforce for all requests
ttl: 120 // keep request IDs for 120s
}
}
| 范围 | 选修的 | 类型 | 默认值 | 示例值 | 环境变量 | 描述 |
|---|---|---|---|---|---|---|
idempotencyOptions | 是的 | Object | undefined | parse_server_experimentim_idempotency_options | 设置此启用指定路径的势力执行。 | |
idempotencyOptions.paths | 是的 | Array<String> | [] | .* (所有路径,包括下面的示例),functions/.* (所有功能),jobs/.* (所有工作),classes/.* (所有类),functions/.* (所有功能),users (用户创建 /更新),installations (安装创建 /更新) | parse_server_experimenty_idempotency_paths | 一系列路径模式必须匹配要启用请求重复数据删除的请求路径。不得包含安装路径,例如与请求路径/parse/functions/myFunction匹配指定路径模式functions/myFunction 。忽略了请求路径的落后斜线,例如路径模式functions/myFunction与/parse/functions/myFunction和/parse/functions/myFunction/ 。 |
idempotencyOptions.ttl | 是的 | Integer | 300 | 60 (60秒) | parse_server_experimenty_idempotency_ttl | 在几秒钟内将请求记录从数据库中丢弃的持续时间。由于网络问题而引起的重复请求,预计将在毫秒内到达几秒钟。该值必须大于0 。 |
要在Postgres中使用此功能,您需要使用PGADMIN创建一个CRON作业,或类似地调用Postgres函数idempotency_delete_expired_records() ,以删除过期的IDEMTOTENCY RECORDS。您可以在下面找到一个示例脚本。确保脚本具有与解析服务器相同的特权。
#! /bin/bash
set -e
psql -v ON_ERROR_STOP=1 --username " $POSTGRES_USER " --dbname " $POSTGRES_DB " << - EOSQL
SELECT idempotency_delete_expired_records();
EOSQL
exec " $@ "假设上面的脚本是命名的, parse_idempotency_delete_expired_records.sh ,每2分钟运行脚本的CRON作业可能看起来像:
2 * * * * /root/parse_idempotency_delete_expired_records.sh > /dev/null 2>&1 谨慎,这是一个实验特征,可能不适合生产。
自定义页面以及功能页面(例如密码重置,电子邮件验证)可以在Parse Server配置中使用pages选项进行本地化:
const api = new ParseServer ( {
... otherOptions ,
pages : {
enableRouter : true , // Enables the experimental feature; required for localization
enableLocalization : true ,
}
}通过将请求提供的locale参数与本地页面内容匹配来实现本地化。可以在请求查询,车身或标题中提供以下键:
localelocalex-parse-page-param-locale例如,密码重置与查询中的语言环境参数的链接可能看起来像:
http://example.com/parse/apps/[appId]/request_password_reset?token=[token]&username=[username]&locale=de-AT
pages.pagesPath path。pages.customUrls ,即使设置了特征页面的本地化(例如密码重置,电子邮件验证),即使设置了customurls。.html文件在本地化自定义页面时进行本地化。页面可以通过两种方式进行本地化:
页面是通过在目录结构中使用相应的文件来本地化的,其中将文件放置在以语言环境或语言命名的子目录中。基本目录中的文件是默认文件。
示例目录结构:
root /
├── public / // pages base path
│ ├── example . html // default file
│ └── de / // de language folder
│ │ └── example . html // de localized file
│ └── de - AT / // de-AT locale folder
│ │ └── example . html // de-AT localized file文件按以下顺序与该语言环境匹配:
de-AT匹配de-AT夹中的文件。de-CH匹配文件夹de中的文件。配置示例:
const api = new ParseServer ( {
... otherOptions ,
pages : {
enableRouter : true , // Enables the experimental feature; required for localization
enableLocalization : true ,
customUrls : {
passwordReset : 'https://example.com/page.html'
}
}
}优点:
缺点:
页面是通过在HTML文件中添加占位符并提供包含翻译以填充占位符的JSON资源的本地本地化的。
示例目录结构:
root /
├── public / // pages base path
│ ├── example . html // the page containing placeholders
├── private / // folder outside of public scope
│ └── translations . json // JSON resource fileJSON资源文件宽松地遵循I18Next语法,该语法通常由翻译平台支持,使其易于管理翻译,导出它们以供Parse服务器使用,甚至可以自动化此工作流程。
示例JSON内容:
{
"en" : { // resource for language `en` (English)
"translation" : {
"greeting" : " Hello! "
}
},
"de" : { // resource for language `de` (German)
"translation" : {
"greeting" : " Hallo! "
}
}
"de-AT" : { // resource for locale `de-AT` (Austrian German)
"translation" : {
"greeting" : " Servus! "
}
}
}配置示例:
const api = new ParseServer ( {
... otherOptions ,
pages : {
enableRouter : true , // Enables the experimental feature; required for localization
enableLocalization : true ,
localizationJsonPath : './private/localization.json' ,
localizationFallbackLocale : 'en'
}
}优点:
缺点:
除了功能相关的默认参数(例如appId和通过JSON资源提供的翻译)之外,还可以将自定义动态占位符定义为路由器配置的一部分。这独立于本地化,也可以使用enableLocalization 。
配置示例:
const api = new ParseServer ( {
... otherOptions ,
pages : {
enableRouter : true , // Enables the experimental feature; required for localization
placeholders : {
exampleKey : 'exampleValue'
}
}
}占位符也可以作为函数或异步函数提供,并且通过locale和其他功能相关参数,以允许动态占位符值:
const api = new ParseServer ( {
... otherOptions ,
pages : {
enableRouter : true , // Enables the experimental feature; required for localization
placeholders : async ( params ) => {
const value = await doSomething ( params . locale ) ;
return {
exampleKey : value
} ;
}
}
} 保留以下参数和占位符密钥,因为它们与密码重置或电子邮件验证等功能相关。它们不应在JSON资源中用作翻译键,也不应用作配置中的手动定义的占位符键: appId , appName , email , error ,Error, locale ,Locale, publicServerUrl ,Token, token , username 。
| 范围 | 选修的 | 类型 | 默认值 | 示例值 | 环境变量 | 描述 |
|---|---|---|---|---|---|---|
pages | 是的 | Object | undefined | - | PARSE_SERVER_PAGES | 诸如密码重置和电子邮件验证等页面的选项。 |
pages.enableRouter | 是的 | Boolean | false | - | PARSE_SERVER_PAGES_ENABLE_ROUTER | 如果应启用页面路由器,则为true ;任何页面选项都需要生效所必需的。谨慎,这是一个实验特征,可能不适合生产。 |
pages.enableLocalization | 是的 | Boolean | false | - | PARSE_SERVER_PAGES_ENABLE_LOCALIZATION | 如果应该本地化页面,则为真实;这对自定义页面重定向没有影响。 |
pages.localizationJsonPath | 是的 | String | undefined | ./private/translations.json | PARSE_SERVER_PAGES_LOCALIZATION_JSON_PATH | JSON文件本地化的路径;这些翻译将根据语言环境填充模板占位符。 |
pages.localizationFallbackLocale | 是的 | String | en | en , en-GB , default | PARSE_SERVER_PAGES_LOCALIZATION_FALLBACK_LOCALE | 如果没有为给定的语言环境提供匹配的翻译,则本地化的后备语言环境。这仅在通过JSON文件提供翻译资源时才相关。 |
pages.placeholders | 是的 | Object , Function , AsyncFunction | undefined | { exampleKey: 'exampleValue' } | PARSE_SERVER_PAGES_PLACEHOLDERS | 将填充的占位符钥匙和值;这可以是一个简单的对象或回调函数。 |
pages.forceRedirect | 是的 | Boolean | false | - | PARSE_SERVER_PAGES_FORCE_REDIRECT | 如果响应应始终是重定向而不满足,则是true ,如果响应类型应取决于请求类型( GET请求 - > content响应; POST request->重定向响应),则为false 。 |
pages.pagesPath | 是的 | String | ./public | ./files/pages ../../pages | PARSE_SERVER_PAGES_PAGES_PATH | 页面目录的路径;这也定义了静态端点/apps所指向的位置。 |
pages.pagesEndpoint | 是的 | String | apps | - | PARSE_SERVER_PAGES_PAGES_ENDPOINT | 页面的API端点。 |
pages.customUrls | 是的 | Object | {} | { passwordReset: 'https://example.com/page.html' } | PARSE_SERVER_PAGES_CUSTOM_URLS | 自定义页面的URL |
pages.customUrls.passwordReset | 是的 | String | password_reset.html | - | PARSE_SERVER_PAGES_CUSTOM_URL_PASSWORD_RESET | 定制页面的URL用于密码重置。 |
pages.customUrls.passwordResetSuccess | 是的 | String | password_reset_success.html | - | PARSE_SERVER_PAGES_CUSTOM_URL_PASSWORD_RESET_SUCCESS | 自定义页面的URL用于密码重置 - >成功。 |
pages.customUrls.passwordResetLinkInvalid | 是的 | String | password_reset_link_invalid.html | - | PARSE_SERVER_PAGES_CUSTOM_URL_PASSWORD_RESET_LINK_INVALID | 定制页面的URL用于密码重置 - >链接无效。 |
pages.customUrls.emailVerificationSuccess | 是的 | String | email_verification_success.html | - | PARSE_SERVER_PAGES_CUSTOM_URL_EMAIL_VERIFICATION_SUCCESS | 自定义页面的URL进行电子邮件验证 - >成功。 |
pages.customUrls.emailVerificationSendFail | 是的 | String | email_verification_send_fail.html | - | PARSE_SERVER_PAGES_CUSTOM_URL_EMAIL_VERIFICATION_SEND_FAIL | 自定义页面的网址进行电子邮件验证 - >链接发送失败。 |
pages.customUrls.emailVerificationSendSuccess | 是的 | String | email_verification_send_success.html | - | PARSE_SERVER_PAGES_CUSTOM_URL_EMAIL_VERIFICATION_SEND_SUCCESS | 自定义页面的URL进行电子邮件验证 - >重新发送链接 - >成功。 |
pages.customUrls.emailVerificationLinkInvalid | 是的 | String | email_verification_link_invalid.html | - | PARSE_SERVER_PAGES_CUSTOM_URL_EMAIL_VERIFICATION_LINK_INVALID | 自定义页面的URL进行电子邮件验证 - >链接无效。 |
pages.customUrls.emailVerificationLinkExpired | 是的 | String | email_verification_link_expired.html | - | PARSE_SERVER_PAGES_CUSTOM_URL_EMAIL_VERIFICATION_LINK_EXPIRED | 自定义页面的URL进行电子邮件验证 - >链接过期。 |
默认情况下,解析服务器将日志:
在解析仪表板中也可以查看日志。
想记录每个请求和响应吗?启动parse-server时,设置VERBOSE环境变量。用法: - VERBOSE='1' parse-server --appId APPLICATION_ID --masterKey MASTER_KEY
想要将日志放在其他文件夹中吗?启动parse-server时,传递PARSE_SERVER_LOGS_FOLDER环境变量。用法: PARSE_SERVER_LOGS_FOLDER='<path-to-logs-folder>' parse-server --appId APPLICATION_ID --masterKey MASTER_KEY
想记录特定级别吗?启动parse-server时传递logLevel参数。用法: - parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --logLevel LOG_LEVEL
是否需要新行界定的JSON错误日志(用于CloudWatch的消费,Google Cloud Logging等)?启动parse-server时,传递JSON_LOGS环境变量。用法: JSON_LOGS='1' parse-server --appId APPLICATION_ID --masterKey MASTER_KEY
请参阅“折旧计划”,以概述折旧和计划的破坏变化。
实时查询旨在用于实时反应性应用程序中,其中仅使用传统查询范式可能会引起几个问题,例如增加响应时间以及高网络和服务器使用情况。在您需要连续更新一个来自数据库的新数据的页面的情况下,应使用实时查询,该数据通常发生在(但不限于)在线游戏,消息传递客户端和共享待办事项列表中。
查看实时查询指南,实时查询服务器设置指南和实时查询协议规范。您可以设置独立服务器或多个实例以进行可扩展性(建议)。
Facebook开发的GraphQL是一种用于API的开源数据查询和操纵语言。除了传统的REST API外,Parse Server还根据您当前的应用程序架构自动生成GraphQL API。 Parse Server还允许您定义自定义的GraphQl查询和突变,它们的解析器可以绑定到您的云代码功能。
运行Parse GraphQl API的最简单方法是通过CLI:
$ npm install -g parse-server mongodb-runner
$ mongodb-runner start
$ parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://localhost/test --publicServerURL http://localhost:1337/parse --mountGraphQL --mountPlayground启动服务器后,您可以在浏览器中访问http:// localhost:1337/Playground,以开始使用GraphQL API。
注意:不要在生产中使用 - 蒙特莱格期选项。 Parse仪表板具有一个内置的GraphQl操场,它是生产应用程序的推荐选项。
您还可以在Docker容器中运行Parse GraphQl API:
$ git clone https://github.com/parse-community/parse-server
$ cd parse-server
$ docker build --tag parse-server .
$ docker run --name my-mongo -d mongo$ docker run --name my-parse-server --link my-mongo:mongo -v config-vol:/parse-server/config -p 1337:1337 -d parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://mongo/test --publicServerURL http://localhost:1337/parse --mountGraphQL --mountPlayground注意:如果要使用云代码,请在上面的命令中添加-v cloud-code-vol:/parse-server/cloud --cloud /parse-server/cloud/main.js 。在启动解析服务器之前,请确保main.js在cloud-code-vol目录中。
启动服务器后,您可以在浏览器中访问http:// localhost:1337/Playground,以开始使用GraphQL API。
注意:不要在生产中使用 - 蒙特莱格期选项。 Parse仪表板具有一个内置的GraphQl操场,它是生产应用程序的推荐选项。
您也可以将GraphQl API与REST API或SOLO一起安装在Express.js应用程序中。您首先需要创建一个新项目并安装所需的依赖项:
$ mkdir my-app
$ cd my-app
$ npm install parse-server express --save然后,创建一个带有以下内容的index.js文件:
const express = require ( 'express' ) ;
const { ParseServer , ParseGraphQLServer } = require ( 'parse-server' ) ;
const app = express ( ) ;
const parseServer = new ParseServer ( {
databaseURI : 'mongodb://localhost:27017/test' ,
appId : 'APPLICATION_ID' ,
masterKey : 'MASTER_KEY' ,
serverURL : 'http://localhost:1337/parse' ,
publicServerURL : 'http://localhost:1337/parse'
} ) ;
const parseGraphQLServer = new ParseGraphQLServer (
parseServer ,
{
graphQLPath : '/graphql' ,
playgroundPath : '/playground'
}
) ;
app . use ( '/parse' , parseServer . app ) ; // (Optional) Mounts the REST API
parseGraphQLServer . applyGraphQL ( app ) ; // Mounts the GraphQL API
parseGraphQLServer . applyPlayground ( app ) ; // (Optional) Mounts the GraphQL Playground - do NOT use in Production
await parseServer . start ( ) ;
app . listen ( 1337 , function ( ) {
console . log ( 'REST API running on http://localhost:1337/parse' ) ;
console . log ( 'GraphQL API running on http://localhost:1337/graphql' ) ;
console . log ( 'GraphQL Playground running on http://localhost:1337/playground' ) ;
} ) ;最后启动您的应用程序:
$ npx mongodb-runner start
$ node index.js启动应用程序后,您可以在浏览器中访问http:// localhost:1337/Playground,以开始使用GraphQL API。
注意:请勿在生产中安装GraphQL操场。 Parse仪表板具有一个内置的GraphQl操场,它是生产应用程序的推荐选项。
运行以下内容:
query Health {
health
}您应该收到以下答复:
{
"data" : {
"health" : true
}
}由于您的应用程序还没有任何架构,因此您可以使用createClass突变来创建您的第一类。运行以下内容:
mutation CreateClass {
createClass (
name : " GameScore "
schemaFields : {
addStrings : [{ name : " playerName " }]
addNumbers : [{ name : " score " }]
addBooleans : [{ name : " cheatMode " }]
}
) {
name
schemaFields {
name
__typename
}
}
}您应该收到以下答复:
{
"data" : {
"createClass" : {
"name" : " GameScore " ,
"schemaFields" : [
{
"name" : " objectId " ,
"__typename" : " SchemaStringField "
},
{
"name" : " updatedAt " ,
"__typename" : " SchemaDateField "
},
{
"name" : " createdAt " ,
"__typename" : " SchemaDateField "
},
{
"name" : " playerName " ,
"__typename" : " SchemaStringField "
},
{
"name" : " score " ,
"__typename" : " SchemaNumberField "
},
{
"name" : " cheatMode " ,
"__typename" : " SchemaBooleanField "
},
{
"name" : " ACL " ,
"__typename" : " SchemaACLField "
}
]
}
}
}解析服务器从您创建的第一堂课中学到了学会,现在您在模式中拥有GameScore类。您现在可以开始使用自动生成的操作!
运行以下以创建您的第一个对象:
mutation CreateGameScore {
createGameScore (
fields : {
playerName : " Sean Plott "
score : 1337
cheatMode : false
}
) {
id
updatedAt
createdAt
playerName
score
cheatMode
ACL
}
}您应该收到与此类似的答复:
{
"data" : {
"createGameScore" : {
"id" : " XN75D94OBD " ,
"updatedAt" : " 2019-09-17T06:50:26.357Z " ,
"createdAt" : " 2019-09-17T06:50:26.357Z " ,
"playerName" : " Sean Plott " ,
"score" : 1337 ,
"cheatMode" : false ,
"ACL" : null
}
}
}您还可以对此新类进行查询:
query GameScores {
gameScores {
results {
id
updatedAt
createdAt
playerName
score
cheatMode
ACL
}
}
}您应该收到与此类似的答复:
{
"data" : {
"gameScores" : {
"results" : [
{
"id" : " XN75D94OBD " ,
"updatedAt" : " 2019-09-17T06:50:26.357Z " ,
"createdAt" : " 2019-09-17T06:50:26.357Z " ,
"playerName" : " Sean Plott " ,
"score" : 1337 ,
"cheatMode" : false ,
"ACL" : null
}
]
}
}
}Parse GraphQL Server允许您创建一个自定义的GraphQL模式,其中包含自己的查询和突变与自动生成的架构合并。您可以使用常规的云代码功能解决这些操作。
要开始创建自定义模式,您需要编码schema.graphql文件,并使用--graphQLSchema和--cloud选项初始化Parse Server:
$ parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://localhost/test --publicServerURL http://localhost:1337/parse --cloud ./cloud/main.js --graphQLSchema ./cloud/schema.graphql --mountGraphQL --mountPlayground为您的schema.graphql和main.js文件使用以下代码。然后重新启动您的解析服务器。
# schema.graphql
extend type Query {
hello : String ! @resolve
} // main.js
Parse . Cloud . define ( 'hello' , async ( ) => {
return 'Hello world!' ;
} ) ;现在,您可以使用GraphQl Playground运行自定义查询:
query {
hello
}您应该收到以下答复:
{
"data" : {
"hello" : " Hello world! "
}
}解析GraphQL指南是学习如何使用Parse GraphQl API的一个很好的来源。
您的GraphQL操场上还拥有一个非常强大的工具。请查看GraphQL操场的右侧。您会看到DOCS和SCHEMA菜单。它们是通过分析您的应用程序架构自动生成的。请参考它们,并了解有关您可以使用Parse GraphQL API的所有内容。
此外,GraphQL学习部分是了解GraphQL语言功能的更多信息。
请参阅贡献指南。
由于所有贡献的人……我们很想在清单上看到您的脸!
通过成为赞助商来支持这个项目。您的徽标将在此处显示您网站的链接。成为赞助商!
每月捐款支持我们,并帮助我们继续我们的活动。成为支持者!
[server-options] http://parseplatform.org/parse-server/api/release/parseserveroptions.html