index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. if (!process.env.DATABASE_URI) {
  7. console.log('DATABASE_URI not specified, falling back to localhost.');
  8. }
  9. var api = new ParseServer({
  10. databaseURI: process.env.DATABASE_URI || 'mongodb://localhost:27017/dev',
  11. cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  12. appId: 'myAppId',
  13. masterKey: 'myMasterKey'
  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. var port = process.env.PORT || 1337;
  27. var httpServer = http.createServer(app);
  28. httpServer.listen(port, function() {
  29. console.log('parse-server-example running on port ' + port + '.');
  30. });