devtools.js
783 Bytes
'use strict';
const fs = require('fs');
const path = require('path');
let devHost = '127.0.0.1';
let devPort = '5006';
fs.readFile(path.join(__dirname, '../../.devhost'), (err, buf)=> {
if (!err) {
let devConfig = JSON.parse(buf.toString());
devHost = devConfig.host || devHost;
devPort = devConfig.port || devPort;
} else if (!process.env.NODE_ENV) {
console.error(err);
console.warn(`
推荐在项目主目录建一个 .devhost 文件,内容为
{
"host": "127.0.0.1"
}
`);
}
});
module.exports = () => {
return (req, res, next) => {
Object.assign(res.locals, {
devHost: devHost,
devPort: devPort
});
next && next();
};
};