index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Example express application adding the parse-server module to expose Parse
  2. // compatible API routes.
  3. var express = require('express');
  4. var ParseServer = require('parse-server').ParseServer;
  5. var path = require('path');
  6. var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
  7. if (!databaseUri) {
  8. console.log('DATABASE_URI not specified, falling back to localhost.');
  9. }
  10. var DB_URI = 'mongodb://'+process.env.MONGO_USER+':'+process.env.MONGO_PASWORD+'@localhost:27017/?replicaSet=rs-db' || 'mongodb://localhost:27017/qrs';
  11. var api = new ParseServer({
  12. //databaseURI: databaseUri || 'mongodb://localhost:27017/qrs',
  13. databaseURI: DB_URI,
  14. cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  15. appId: process.env.APPLICATION_ID_QRS || 'myAppId',
  16. masterKey: process.env.MASTER_KEY_QRX || '', //Add your master key here. Keep it secret!
  17. serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
  18. liveQuery: {
  19. classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
  20. }
  21. });
  22. console.log(DB_URI);
  23. console.log(process.env.MASTER_KEY_QRX);
  24. console.log(process.env.SERVER_URL);
  25. // Client-keys like the javascript key or the .NET key are not necessary with parse-server
  26. // If you wish you require them, you can set them as options in the initialization above:
  27. // javascriptKey, restAPIKey, dotNetKey, clientKey
  28. var app = express();
  29. // Serve static assets from the /public folder
  30. app.use('/public', express.static(path.join(__dirname, '/public')));
  31. // Serve the Parse API on the /parse URL prefix
  32. var mountPath = process.env.PARSE_MOUNT || '/parse';
  33. app.use(mountPath, api);
  34. // Parse Server plays nicely with the rest of your web routes
  35. app.get('/', function(req, res) {
  36. res.status(200).send('I dream of being a website. Please star the parse-server repo on GitHub!');
  37. });
  38. // There will be a test page available on the /test path of your server url
  39. // Remove this before launching your app
  40. app.get('/test', function(req, res) {
  41. res.sendFile(path.join(__dirname, '/public/test.html'));
  42. });
  43. var port = process.env.PORT || 1337;
  44. var httpServer = require('http').createServer(app);
  45. httpServer.listen(port, function() {
  46. console.log('parse-server-example running on port ' + port + '.');
  47. });
  48. // This will enable the Live Query real-time server
  49. ParseServer.createLiveQueryServer(httpServer);