|
|
'use strict';
|
|
|
|
|
|
const os = require('os');
|
|
|
const fs = require('fs');
|
|
|
let devHost = 'localhost';
|
|
|
let devHost;
|
|
|
|
|
|
fs.readFile('.devhost', (err, buf)=> {
|
|
|
if (!err) {
|
|
|
devHost = JSON.parse(buf.toString()).host;
|
|
|
}
|
|
|
});
|
|
|
const getFirstLocalIp = () => {
|
|
|
const ifaces = os.networkInterfaces();
|
|
|
const res = [];
|
|
|
|
|
|
Object.keys(ifaces).forEach(function(ifname) {
|
|
|
ifaces[ifname].forEach(function(iface) {
|
|
|
if ('IPv4' !== iface.family || iface.internal !== false) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
res.push(iface.address);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
return res[0] || 'localhost';
|
|
|
};
|
|
|
|
|
|
if (!devHost) {
|
|
|
fs.readFile('.devhost', (err, buf) => {
|
|
|
if (!err) {
|
|
|
devHost = JSON.parse(buf.toString()).host;
|
|
|
} else {
|
|
|
devHost = getFirstLocalIp();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
module.exports = () => {
|
|
|
return (req, res, next) => {
|
...
|
...
|
@@ -17,4 +39,4 @@ module.exports = () => { |
|
|
|
|
|
next();
|
|
|
};
|
|
|
}; |
|
|
}; |
|
|
\ No newline at end of file |
...
|
...
|
|