Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. const Liana = require('forest-express-sequelize');
  2. const express = require('express');
  3. const initCollections = require('./collections');
  4. const initModels = require('./models');
  5. const Sequelize = require('sequelize');
  6.  
  7. const sequelize = new Sequelize({
  8. dialect: 'sqlite',
  9. storage: 'database.sqlite',
  10. });
  11.  
  12. const models = initModels(sequelize);
  13.  
  14. const app = express();
  15.  
  16. // We can get rid of modelsDir, because all the models informations are in sequelize and
  17. // mongoose instances.
  18. // Here the example could also work with a factory instead (`const liana = createLiana({...})`).
  19. const liana = new Liana({
  20. envSecret: process.env.FOREST_ENV_SECRET,
  21. authSecret: process.env.FOREST_AUTH_SECRET,
  22. sequelize: models.sequelize,
  23. });
  24.  
  25. // To initialize a collection, just call a member function. This is a more familiar way to do
  26. // for nodejs users than a static function of the forest-express-sequelize module. It is
  27. // rarely a good idea to use a module as singleton, difficult to understand what is the inner logic,
  28. // like how the static functions are related to the initialization. Also,
  29. // a singleton forbid to have multiple instances of the liana in the same app.
  30. liana.collection('user', {});
  31.  
  32. // And we can still put the collections initializations in a folder if we need. This is very
  33. // straightforward, no documentation is needed (and potentially less support), we just do like we
  34. // would do with anything in nodejs. Again familiarity is key.
  35. // Also, we can get rid of the `configDir` option.
  36. initCollections(liana);
  37.  
  38. app.use(liana.createMiddleware());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement