1234567891011121314151617181920212223242526272829 |
- 'use strict';
- /**
- * @param {Egg.Application} app - egg application
- */
- const os = require('os');
- function getIPAdress() {
- const interfaces = os.networkInterfaces();
- for (const devName in interfaces) {
- const iface = interfaces[devName];
- for (let i = 0; i < iface.length; i++) {
- const alias = iface[i];
- if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
- return alias.address;
- }
- }
- }
- }
- module.exports = app => {
- const { router, controller } = app;
- const { routePrefix, cluster } = app.config;
- const ipAddress = getIPAdress();
- console.log(`前缀:http://${ipAddress}:${cluster.listen.port}${routePrefix}`);
- console.log();
- router.get(routePrefix, controller.home.index);
- router.get(`${routePrefix}/diskInfo`, controller.home.diskInfo);
- router.post(`${routePrefix}/dir`, controller.home.toDir);
- router.post(`${routePrefix}/delFile`, controller.home.delFile);
- };
|