index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 path = require('path');
  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: 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/parse' // 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. // Config static middleware for assets
  22. app.use('/static', express.static(path.join(__dirname, '/public')));
  23. // Serve the Parse API on the /parse URL prefix
  24. var mountPath = process.env.PARSE_MOUNT || '/parse';
  25. app.use(mountPath, api);
  26. // Parse Server plays nicely with the rest of your web routes
  27. app.get('/', function(req, res) {
  28. res.status(200).send('I dream of being a web site.');
  29. });
  30. // If you are migrating a webapp hosted on domain.parseapp.com:
  31. // Remove statement above serving the 200 status (app.get('/ function()});
  32. // Uncomment app.use below and set the absolute path for serving files in the /public dir
  33. // app.use(express.static(__dirname + '/public'));
  34. app.get('/test', function(req, res) {
  35. res.sendFile(path.join(__dirname, '/public/test.html'));
  36. });
  37. var port = process.env.PORT || 1337;
  38. app.listen(port, function() {
  39. console.log('parse-server-example running on port ' + port + '.');
  40. });