index.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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' // 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. app.get('/test', function(req, res) {
  31. res.sendFile(path.join(__dirname, '/public/test.html'));
  32. });
  33. var port = process.env.PORT || 1337;
  34. app.listen(port, function() {
  35. console.log('parse-server-example running on port ' + port + '.');
  36. });