api.js 562 B

123456789101112131415161718192021222324252627
  1. module.exports = {
  2. init: (cb) => {
  3. const { app } = require('./app.js');
  4. const actions = require('./actions');
  5. app.get('/', (req, res) => {
  6. res.json({
  7. status: 'success',
  8. message: 'Coming Soon'
  9. });
  10. });
  11. Object.keys(actions).forEach((namespace) => {
  12. Object.keys(actions[namespace]).forEach((action) => {
  13. let name = `/${namespace}/${action}`;
  14. app.get(name, (req, res) => {
  15. actions[namespace][action](null, (result) => {
  16. if (typeof cb === 'function') return res.json(result);
  17. });
  18. });
  19. })
  20. });
  21. cb();
  22. }
  23. }