-
-
Save dyaa/5617f52f2199b27e3d5cf1f1ef3654c6 to your computer and use it in GitHub Desktop.
Parse Separate Live Query Server 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 Parse Live Query Server, running on a separate EC2 instance | |
var express = require('express'); | |
var cors = require('cors') | |
var ParseServer = require('parse-server').ParseServer; | |
var app = express(); | |
app.use(cors()); | |
// We include the lines below so that we can hit `/` and it passes the Elastic Beanstalk Health Check | |
app.get('/', function(req, res) { | |
res.status(200).send('Make sure to star the parse-server repo on GitHub!'); | |
}); | |
var port = process.env.PORT || 1338; | |
var httpServer = require('http').createServer(app); | |
httpServer.listen(port, function() { | |
console.log('parse-server-example running on port ' + port + '.'); | |
}); | |
ParseServer.createLiveQueryServer(httpServer, { | |
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, // socket.myApp.com | |
javascriptKey: process.env.JAVASCRIPT_KEY, | |
redisURL: process.env.redisURL || "redis://:{password}@redis-123456.c11.us-east-1-3.ec2.cloud.redislabs.com:18091", // this is optional, include only if you're using Redis | |
websocketTimeout: 10 * 1000, | |
cacheTimeout: 60 * 600 * 1000, | |
verbose: process.env.VERBOSE_KEY || false, | |
}); |
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 above | |
masterKey: process.env.MASTER_KEY, // same as index.js file above | |
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" // this is optional, include only if you're using Redis | |
}, | |
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 + '.'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment