Last active
February 5, 2019 23:06
-
-
Save zackshapiro/279d4acf83e81da0ea03f3553619ef87 to your computer and use it in GitHub Desktop.
Single Server Live Query Setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is the index.js file for my main app | |
var express = require('express'); | |
var cors = require('cors') | |
var ParseServer = require('parse-server').ParseServer; | |
var path = require('path'); | |
var bodyParser = require('body-parser'); | |
var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI; | |
if (!databaseUri) { | |
console.log('DATABASE_URI not specified, falling back to localhost.'); | |
} | |
// NOTE: `production` should be false if dev or local | |
// Always set to true when deploying to `master`. | |
var S3Adapter = require('parse-server').S3Adapter; | |
var s3Adapter = new S3Adapter( | |
process.env.S3BUCKET || 'media', | |
{ ... } | |
); | |
var api = new ParseServer({ | |
databaseURI: databaseUri, | |
cloud: process.env.CLOUD_CODE_MAIN, | |
appId: process.env.APP_ID, // same as index.js file below | |
masterKey: process.env.MASTER_KEY, // same as index.js file below | |
serverURL: process.env.SERVER_URL, // live.myApp.com | |
javascriptKey: process.env.JAVASCRIPT_KEY, | |
clientKey: process.env.CLIENT_KEY, | |
filesAdapter: s3Adapter, | |
verbose: process.env.VERBOSE_KEY || false, | |
allowClientClassCreation: process.env.CLIENT_CREATION || false, | |
liveQuery: { | |
classNames: ['messages', '_User'], | |
redisURL: process.env.redisURL || "redis://:{password}@redis-123456.c11.us-east-1-3.ec2.cloud.redislabs.com:18091" | |
}, | |
databaseOptions: { poolSize: 500 }, | |
maxUploadSize: "5mb" | |
}); | |
var app = express(); | |
app.use(bodyParser.json({limit: '5mb'}) ); | |
app.use(bodyParser.urlencoded({limit: '5mb', extended: true})); | |
app.use(cors()); | |
app.use('/public', express.static(path.join(__dirname, '/public'))); | |
var mountPath = process.env.PARSE_MOUNT || '/parse'; | |
app.use(mountPath, api); | |
app.get('/', function(req, res) { | |
res.status(200).send('Make sure to star the parse-server repo on GitHub!'); | |
}); | |
var port = process.env.PORT || 1337; | |
var httpServer = require('http').createServer(app); | |
httpServer.listen(port, function() { | |
console.log('parse-server-example running on port ' + port + '.'); | |
}); | |
ParseServer.createLiveQueryServer(httpServer); |
Is there an https version of the same?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: line 62 is where we create a separate server instance of a Live Query Server