Advertisement
Guest User

app.js

a guest
Feb 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const path = require('path');
  2. const favicon = require('serve-favicon');
  3. const compress = require('compression');
  4. const cors = require('cors');
  5. const helmet = require('helmet');
  6. const logger = require('winston');
  7.  
  8. const feathers = require('@feathersjs/feathers');
  9. const configuration = require('@feathersjs/configuration');
  10. const express = require('@feathersjs/express');
  11.  
  12.  
  13.  
  14. const middleware = require('./middleware');
  15. const services = require('./services');
  16. const appHooks = require('./app.hooks');
  17. const channels = require('./channels');
  18.  
  19. const app = express(feathers());
  20.  
  21. // Load app configuration
  22. app.configure(configuration());
  23. // Enable CORS, security, compression, favicon and body parsing
  24. app.use(cors());
  25. app.use(helmet());
  26. app.use(compress());
  27. app.use(express.json());
  28. app.use(express.urlencoded({ extended: true }));
  29. app.use(favicon(path.join(app.get('public'), 'favicon.ico')));
  30. class Messages {
  31.   constructor() {
  32.     this.messages = [];
  33.     this.currentId = 0;
  34.   }
  35. }
  36.  
  37. // Host the public folder
  38. app.use('/', express.static(app.get('public')));
  39.  
  40. // Set up Plugins and providers
  41. app.configure(express.rest());
  42.  
  43. app.use('messages', new Messages());
  44.  
  45. // Configure other middleware (see `middleware/index.js`)
  46. app.configure(middleware);
  47. // Set up our services (see `services/index.js`)
  48. app.configure(services);
  49. // Set up event channels (see channels.js)
  50. app.configure(channels);
  51.  
  52. // Configure a middleware for 404s and the error handler
  53. app.use(express.notFound());
  54. app.use(express.errorHandler({ logger }));
  55.  
  56. app.hooks(appHooks);
  57.  
  58. app.service('messages').create({
  59.   text: 'Hello from the server'
  60. });
  61.  
  62. module.exports = app;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement