Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. const path = require('path');
  2. const serveStatic = require('feathers').static;
  3. const favicon = require('serve-favicon');
  4. const compress = require('compression');
  5. const cors = require('cors');
  6. const feathers = require('feathers');
  7. const configuration = require('feathers-configuration');
  8. const hooks = require('feathers-hooks');
  9. const rest = require('feathers-rest');
  10. const bodyParser = require('body-parser');
  11. const auth = require('feathers-authentication');
  12. const socketio = require('feathers-socketio');
  13. const jwt = require('feathers-authentication-jwt');
  14. const local = require('feathers-authentication-local');
  15. const middleware = require('./middleware');
  16. const services = require('./services');
  17.  
  18. const mongoose = require('mongoose');
  19. const service = require('feathers-mongoose');
  20.  
  21. const foodModel = require('./models/foodModel');
  22. const orderModel = require('./models/orderModel');
  23. mongoose.Promise = global.Promise;
  24. mongoose.connect('mongodb://localhost:27017/feathers');
  25.  
  26. const app = feathers();
  27.  
  28. app.configure(configuration(path.join(__dirname, '..')));
  29.  
  30. let socketioOptions = function(io) {
  31. io.on('connection', function(socket) {
  32. socket.emit('test', { text: 'A client connected! This message is sent right after connecting.' });
  33. socket.on('test', function (data) {
  34. console.log(data);
  35. });
  36. });
  37.  
  38. // Registering Socket.io middleware
  39. io.use(function (socket, next) {
  40. // Exposing a request property to services and hooks
  41. socket.feathers.referrer = socket.request.referrer;
  42. next();
  43. });
  44. };
  45.  
  46. app.use(compress())
  47. .options('*', cors())
  48. .use(cors())
  49. .use(favicon( path.join(app.get('public'), 'favicon.ico') ))
  50. .use('/', serveStatic( app.get('public') ))
  51. .use(bodyParser.json())
  52. .use(bodyParser.urlencoded({ extended: true }))
  53. .configure(hooks())
  54. .configure(rest())
  55. .configure(socketio())
  56. .configure(services)
  57. .configure(middleware)
  58. .configure(jwt())
  59. .configure(local());
  60.  
  61. app.service('authentication').hooks({
  62. before: {
  63. create: [
  64. auth.hooks.authenticate(['jwt', 'local'])
  65. ]
  66. }
  67. });
  68.  
  69. module.exports = app;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement