index.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 databaseUri = process.env.DATABASE_URI || process.env.MONGOLAB_URI;
  6. if (!databaseUri) {
  7. console.log('DATABASE_URI not specified, falling back to localhost.');
  8. }
  9. var api = new ParseServer({
  10. serverURL: process.env.PARSE_SERVER_URL,
  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 || 'myMasterKey'
  15. });
  16. // Client-keys like the javascript key or the .NET key are not necessary with parse-server
  17. // If you wish you require them, you can set them as options in the initialization above:
  18. // javascriptKey, restAPIKey, dotNetKey, clientKey
  19. var app = express();
  20. // Serve the Parse API on the /parse URL prefix
  21. var mountPath = process.env.PARSE_MOUNT || '/parse';
  22. app.use(mountPath, api);
  23. // Parse Server plays nicely with the rest of your web routes
  24. app.get('/', function(req, res) {
  25. res.status(200).send('I dream of being a web site.');
  26. });
  27. var port = process.env.PORT || 1337;
  28. app.listen(port, function() {
  29. console.log('parse-server-example running on port ' + port + '.');
  30. });