router.js 951 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. /**
  3. * @param {Egg.Application} app - egg application
  4. */
  5. const os = require('os');
  6. function getIPAdress() {
  7. const interfaces = os.networkInterfaces();
  8. for (const devName in interfaces) {
  9. const iface = interfaces[devName];
  10. for (let i = 0; i < iface.length; i++) {
  11. const alias = iface[i];
  12. if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
  13. return alias.address;
  14. }
  15. }
  16. }
  17. }
  18. module.exports = app => {
  19. const { router, controller } = app;
  20. const { routePrefix, cluster } = app.config;
  21. const ipAddress = getIPAdress();
  22. console.log(`前缀:http://${ipAddress}:${cluster.listen.port}${routePrefix}`);
  23. console.log();
  24. router.get(routePrefix, controller.home.index);
  25. router.get(`${routePrefix}/diskInfo`, controller.home.diskInfo);
  26. router.post(`${routePrefix}/dir`, controller.home.toDir);
  27. router.post(`${routePrefix}/delFile`, controller.home.delFile);
  28. };