index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 || '', //Add your master key here. Keep it secret!
  15. serverUrl: process.env.SERVER_URL || 'http://localhost:1337' // Don't forget to change to https if needed
  16. });
  17. // Client-keys like the javascript key or the .NET key are not necessary with parse-server
  18. // If you wish you require them, you can set them as options in the initialization above:
  19. // javascriptKey, restAPIKey, dotNetKey, clientKey
  20. var app = express();
  21. // Serve the Parse API on the /parse URL prefix
  22. var mountPath = process.env.PARSE_MOUNT || '/parse';
  23. app.use(mountPath, api);
  24. // Parse Server plays nicely with the rest of your web routes
  25. app.get('/', function(req, res) {
  26. res.status(200).send('I dream of being a web site.');
  27. });
  28. var port = process.env.PORT || 1337;
  29. app.listen(port, function() {
  30. console.log('parse-server-example running on port ' + port + '.');
  31. });