Advertisement
purxiz

Untitled

Apr 17th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // server.js
  2.  
  3. // BASE SETUP
  4. // =============================================================================
  5. var mongoose = require('mongoose');
  6. mongoose.Promise = global.Promise;
  7. mongoose.connect('mongodb://localhost:28888/ybtc', {useMongoClient: true}); //connect to database
  8.  
  9.  
  10.  
  11.  
  12.  
  13. // call the packages we need
  14. var express    = require('express');        // call express
  15. var app        = express();                 // define our app using express
  16. var bodyParser = require('body-parser');    // allows us to process html requests
  17. var cors       = require('cors');                       // for managing which servers can access API
  18.  
  19.  
  20. var corsOptions = {
  21.  
  22.     origin: 'http://107.170.255.130'
  23.  
  24. };
  25.  
  26. app.use(cors(corsOptions));
  27.  
  28. // configure app to use bodyParser()
  29. // this will let us get the data from a POST
  30. app.use(bodyParser.urlencoded({ extended: true }));
  31. app.use(bodyParser.json());
  32.  
  33. var port = process.env.PORT || 8080;        // set our port
  34.  
  35.  
  36. // REGISTER OUR ROUTES -------------------------------
  37. // all of our routes will be prefixed with /api
  38. app.use('/api/users', require('../routes/users'));
  39. app.use('/api/events', require('../routes/events'));
  40. app.use('/api/messages', require('../routes/messages'));
  41.  
  42. // START THE SERVER
  43. // =============================================================================
  44. app.listen(port);
  45. console.log('Magic happens on port ' + port);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement