app.js 849 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * Main application file
  3. */
  4. 'use strict';
  5. var express = require('express');
  6. var app = express();
  7. var mongoose = require('mongoose');
  8. mongoose.connect('mongodb://localhost/eba');
  9. require('./routes')(app);
  10. app.get('/', function (req, res) {
  11. res.send('Hello World!')
  12. })
  13. function allowCrossDomain(req, res, next) {
  14. res.header('Access-Control-Allow-Origin', '*');
  15. res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
  16. res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
  17. // intercept OPTIONS method
  18. if ('OPTIONS' === req.method) {
  19. res.send(200);
  20. }
  21. else {
  22. next();
  23. }
  24. }
  25. app.use(allowCrossDomain);
  26. try {
  27. app.listen(3000, function () {
  28. console.log('Example app listening on port 3000!')
  29. })
  30. } catch (error) {
  31. console.error(error);
  32. }