Search code examples
javascriptnode.jsparse-platformroutesparse-server

Running a Parse Server cloud function at a given route


I have a Cloud function defined as:

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

I can access it at 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

I tried to change the definition as follow but it doesn't work:

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

Any idea?


Solution

  • If think the better way to do that is to replace parse by the current version of you API

    For example when you deploy your parse-server add the version of your API: http://127.0.0.1:1338/v1.0/functions/getTravel

    You can do that with the PARSE_MOUNT variable in your env

    If you want to have a single instance that run multiple version, just create multiple ParseServer and serve it like that :

    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