Skip to content

Instantly share code, notes, and snippets.

@ananfang
Last active August 11, 2020 12:07
Show Gist options
  • Select an option

  • Save ananfang/a8d917ec88ff7e033bcceff1654fe737 to your computer and use it in GitHub Desktop.

Select an option

Save ananfang/a8d917ec88ff7e033bcceff1654fe737 to your computer and use it in GitHub Desktop.

Revisions

  1. ananfang revised this gist Aug 29, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion scalable-parse-livequery-server.js
    Original file line number Diff line number Diff line change
    @@ -43,4 +43,4 @@ subscription.handle(Event.created, { query, object in
    /* Handle CREATE event */
    })

    // In the end, we can scale web process in LiveQuery app ^_^
    // In the end, we can scale web process in LiveQuery app on Heroku ^_^
  2. ananfang revised this gist Aug 29, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion scalable-parse-livequery-server.js
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ var api = new ParseServer({
    appId: APP_ID_ON_LIVEQUERY,
    masterKey: MASTER_KEY_ON_LIVEQUERY,
    serverURL: SERVER_URL_ON_LIVEQUERY,
    databaseURI: DATABASE_URI_ON_LIVEQUERY // (Optional) Even if leave this default, it will only get warning
    databaseURI: // (Optional) Even if leave this default, it will only get warning
    });
    // Step B3. Create LiveQuery server
    var app = express();
  3. ananfang created this gist Aug 29, 2017.
    46 changes: 46 additions & 0 deletions scalable-parse-livequery-server.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    // This gist explains how to setup scalable Parse LiveQuery server on Heroku
    // Because there is one and only 'web' process on Heroku, it will divide into two Heroku apps: Main and LiveQuery.

    // A: Main app - All features except for LiveQuery server
    // Step A1. Setup a Parse app on Heroku
    // Step A2. Add a Heroku Redis (free plan is enough for testing)
    // Step A3. Configure Parse app, add redisURL for liveQuery
    var api = new ParseServer({
    ...
    liveQuery: {
    classNames: [...],
    redisURL: REDIS_URL_ON_MAIN
    },
    ...
    });

    // B: LiveQuery app - A scalable LiveQuery server for Main app
    // Step B1. Steup another Parse app on Heroku
    // Step B2. Configure Parse app, DO NOT set liveQuery
    var api = new ParseServer({
    appId: APP_ID_ON_LIVEQUERY,
    masterKey: MASTER_KEY_ON_LIVEQUERY,
    serverURL: SERVER_URL_ON_LIVEQUERY,
    databaseURI: DATABASE_URI_ON_LIVEQUERY // (Optional) Even if leave this default, it will only get warning
    });
    // Step B3. Create LiveQuery server
    var app = express();
    app.use(PARSE_MOUNT_ON_LIVEQUERY, api);

    var httpServer = require('http').createServer(app);
    httpServer.listen(PORT_ON_LIVEQUERY, function() {/* Create HTTP server successfully */});

    ParseServer.createLiveQueryServer(httpServer, {
    redisURL: REDIS_URL_ON_MAIN // Redis URL from Mani app
    });

    // C: Client side - Swift for example
    // Step C1. Init Client instance using Client(server:applicationId:clientKey:)
    let client = Client(server: SERVER_URL_ON_LIVEQUERY, applicationId: APP_ID_ON_LIVEQUERY, clientKey: nil)
    // Step C2. Subscribe for LiveQuery
    let subscription = client.subscribe(query)
    subscription.handle(Event.created, { query, object in
    /* Handle CREATE event */
    })

    // In the end, we can scale web process in LiveQuery app ^_^