index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
  11. cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  12. appId: process.env.APP_ID || 'myAppId',
  13. masterKey: process.env.MASTER_KEY || '' //Add your master key here. Keep it secret!
  14. });
  15. // Client-keys like the javascript key or the .NET key are not necessary with parse-server
  16. // If you wish you require them, you can set them as options in the initialization above:
  17. // javascriptKey, restAPIKey, dotNetKey, clientKey
  18. var app = express();
  19. // Serve the Parse API on the /parse URL prefix
  20. var mountPath = process.env.PARSE_MOUNT || '/parse';
  21. app.use(mountPath, api);
  22. // Parse Server plays nicely with the rest of your web routes
  23. app.get('/', function(req, res) {
  24. res.status(200).send('I dream of being a web site.');
  25. });
  26. // If you are migrating a webapp hosted on domain.parseapp.com:
  27. // Remove statement above serving the 200 status (app.get('/ function()});
  28. // Uncomment app.use below and set the absolute path for serving files in the /public dir
  29. // app.use(express.static(__dirname + '/public'));
  30. var port = process.env.PORT || 1337;
  31. app.listen(port, function() {
  32. console.log('parse-server-example running on port ' + port + '.');
  33. });