index.js 2.1 KB

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