index.js 1.3 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 http = require('http');
  6. var databaseUri = process.env.DATABASE_URI || process.env.MONGOLAB_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: 'myAppId',
  14. masterKey: '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. var httpServer = http.createServer(app);
  29. httpServer.listen(port, function() {
  30. console.log('parse-server-example running on port ' + port + '.');
  31. });