简体   繁体   English

在给定的路由上运行Parse Server云功能

[英]Running a Parse Server cloud function at a given route

I have a Cloud function defined as: 我有一个Cloud函数定义为:

Parse.Cloud.define('getTravel', function (request, response) {...

I can access it at http://127.0.0.1:1338/parse/functions/getTravel 我可以在http://127.0.0.1:1338/parse/functions/getTravel上访问它

I want to version my API and serve it at http://127.0.0.1:1338/parse/functions/v1/getTravel 我想对我的API进行版本控制,并在http://127.0.0.1:1338/parse/functions/v1/getTravel中提供它

I tried to change the definition as follow but it doesn't work: 我试图按如下方式更改定义,但它不起作用:

Parse.Cloud.define('getTravel', function (request, response) {...

Any idea? 任何想法?

If think the better way to do that is to replace parse by the current version of you API 如果认为更好的方法是用当前版本的API代替parse

For example when you deploy your parse-server add the version of your API: http://127.0.0.1:1338/v1.0/functions/getTravel 例如,当您部署解析服务器时,请添加API版本: http : //127.0.0.1 : 1338/v1.0/functions/getTravel

You can do that with the PARSE_MOUNT variable in your env 您可以在环境中使用PARSE_MOUNT变量来完成此操作

If you want to have a single instance that run multiple version, just create multiple ParseServer and serve it like that : 如果您想拥有一个运行多个版本的实例,只需创建多个ParseServer并按以下方式提供服务:

var v1 = new ParseServer({
  databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/v1/main.js',
  appId: process.env.APP_ID || 'myAppId',
  masterKey: process.env.MASTER_KEY || '',
  serverURL: process.env.SERVER_URL || 'http://localhost:1337/v1',
  liveQuery: {
    classNames: ["Posts", "Comments"]
  }
});

var v2 = new ParseServer({
  databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/v2/main.js',
  appId: process.env.APP_ID || 'myAppId',
  masterKey: process.env.MASTER_KEY || '',
  serverURL: process.env.SERVER_URL || 'http://localhost:1337/v2',
});

app.use('/v1', api);
app.use('/v2', api);

Note: At this level with parse you can't make url like http://127.0.0.1:1338/parse/functions/v1/getTravel without fork it 注意:在此级别,您无法使用fork进行解析,例如http://127.0.0.1:1338/parse/functions/v1/getTravel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM