api.js 670 B

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