index.js 2.3 KB

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