Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
/* eslint no-console: 0 */
const address = require('address');
const qrcode = require('qrcode-terminal');
const webpack = require('webpack');
const pathConfig = require('./path.config');
const webpackConfigBase = require('./webpack.config.base');
const envConfig = require('./env.config');
const webpackConfigDev = Object.assign({}, webpackConfigBase);
const ipv4 = address.ip();
const port = envConfig.port;
const webUrl = 'http://' + ipv4 + ':' + port;
const bundleUrl = 'http://' + ipv4 + ':' + port + '/js/index.bundle.js';
const weexBundleUrl = `${bundleUrl}?_wx_tpl=${bundleUrl}`;
qrcode.generate(webUrl, { small: true });
console.log('Web: scan above QRCode ' + webUrl + ' or direct open in browser.\n');
qrcode.generate(weexBundleUrl, { small: true });
console.log('Weex: scan above QRCode ' + weexBundleUrl + ' use weex playground.\n');
// enable source map
webpackConfigDev.devtool = 'inline-module-source-map';
webpackConfigDev.entry = {
'index.bundle': [pathConfig.appIndexJs]
};
/* eslint-disable */
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const autoprefixer = require('autoprefixer');
const pxtorem = require('postcss-pxtorem');
const OpenBrowserPlugin = require('open-browser-webpack-plugin');
const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent');
const address = require('address');
const ip = address.ip();
function resolve(dir) {
return path.join(__dirname, '..', dir);
}
const createLintingRule = () => ({});
// common function to get css loaders
const getStyleLoaders = (cssOptions, preProcessor, preProcessorOptions) => {
const loaders = [
require.resolve('style-loader'),
{
loader: require.resolve('css-loader'),
options: cssOptions,
},
{
// Options for PostCSS as we reference these options twice
}
// Unfortunately, many languages (unlike node) do not yet support IPv6.
// This means even though localhost resolves to ::1, the application
// must fall back to IPv4 (on 127.0.0.1).
// We can re-enable this in a few years.
/*try {
o.hostname = address.ipv6() ? '::1' : '127.0.0.1';
} catch (_ignored) {
o.hostname = '127.0.0.1';
}*/
try {
// Check if we're on a network; if we are, chances are we can resolve
// localhost. Otherwise, we can just be safe and assume localhost is
// IPv4 for maximum compatibility.
if (!address.ip()) {
o.hostname = '127.0.0.1';
}
} catch (_ignored) {
o.hostname = '127.0.0.1';
}
return url.format(o);
}
config.middleware = [];
// 线上环境此处替换为项目根域名 例如:blog.seosiwei.com (这里不需要填写http|https和斜杠等字符)
// 用于安全校验和回调域名根路径 开发路径域名
config.host = '127.0.0.1';
config.port = 7001;
config.origin = `http://${config.host}:${config.port}`;
// 集群配置(一般默认即可)
config.cluster = {
listen: {
port: config.port,
hostname: '127.0.0.1',
ip: address.ip(),
},
};
// 用户密码加盐随机值
config.user_pwd_salt_addition = 'ZANEHELLOBEAUTIFUL';
// 用户登录态持续时间 1 天
config.user_login_timeout = 86400;
// web浏览器端定时任务是否执行
config.is_web_task_run = true;
// wx小程序端定时任务是否执行
config.is_wx_task_run = true;
// 执行pvuvip定时任务的时间间隔 每2分钟定时执行一次 (可更改)
}
// Unfortunately, many languages (unlike node) do not yet support IPv6.
// This means even though localhost resolves to ::1, the application
// must fall back to IPv4 (on 127.0.0.1).
// We can re-enable this in a few years.
/*try {
o.hostname = address.ipv6() ? '::1' : '127.0.0.1';
} catch (_ignored) {
o.hostname = '127.0.0.1';
}*/
try {
// Check if we're on a network; if we are, chances are we can resolve
// localhost. Otherwise, we can just be safe and assume localhost is
// IPv4 for maximum compatibility.
if (!address.ip()) {
o.hostname = '127.0.0.1';
}
} catch (_ignored) {
o.hostname = '127.0.0.1';
}
return url.format(o);
}
listen(port, 'localhost', err => {
if (err) {
return handleError(err);
}
// 4. check current ip
let ip;
try {
ip = address.ip();
} catch (err) {
// Skip the `ip` check if `address.ip()` fails
return callback(null, realPort);
}
listen(port, ip, (err, realPort) => {
if (err) {
return handleError(err);
}
callback(null, realPort);
});
});
});
contentBase: false, // since we use CopyWebpackPlugin.
compress: true,
host: HOST || config.dev.host,
port: PORT || config.dev.port,
open: config.dev.autoOpenBrowser,
overlay: config.dev.errorOverlay ? { warnings: false, errors: true } : false,
publicPath: config.dev.assetsPublicPath,
proxy: config.dev.proxyTable,
quiet: true, // necessary for FriendlyErrorsPlugin
watchOptions: {
poll: config.dev.poll,
aggregateTimeout: 1000,
ignored: [config.build.assetsRoot, path.resolve(__dirname, "../config"), __dirname],
},
disableHostCheck: true,
public: address.ip(),
},
optimization: {
minimize: false,
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
new webpack.NoEmitOnErrorsPlugin(),
],
});
module.exports = new Promise((resolve, reject) => {
portfinder.basePort = process.env.PORT || config.dev.port;
portfinder.getPort((err, port) => {
if (err) {
reject(err);
}
// Unfortunately, many languages (unlike node) do not yet support IPv6.
// This means even though localhost resolves to ::1, the application
// must fall back to IPv4 (on 127.0.0.1).
// We can re-enable this in a few years.
/* try {
o.hostname = address.ipv6() ? '::1' : '127.0.0.1';
} catch (_ignored) {
o.hostname = '127.0.0.1';
} */
try {
// Check if we're on a network; if we are, chances are we can resolve
// localhost. Otherwise, we can just be safe and assume localhost is
// IPv4 for maximum compatibility.
if (!address.ip()) {
o.hostname = '127.0.0.1'
}
} catch (_) {
o.hostname = '127.0.0.1'
}
return url.format(o)
}
const certStore = {
rootCaCert: fs.readFileSync(__dirname + '/../cert/root/rootCA.crt', 'utf8'),
rootCaKey: fs.readFileSync(__dirname + '/../cert/root/rootCA.key', 'utf8'),
defaultCaCert: fs.readFileSync(__dirname + '/../cert/wwe.crt', 'utf8'),
defaultCaKey: fs.readFileSync(__dirname + '/../cert/wwe.key', 'utf8')
};
const proxy = new FFRKProxy(certStore);
let proxyIp = config.get('application.proxy.ip');
const proxyPort = config.get('application.proxy.port');
let staticIp = config.get('application.cert.ip');
const staticPort = config.get('application.cert.port');
if (proxyIp === '0.0.0.0') {
proxyIp = address.ip();
}
if (staticIp === '0.0.0.0') {
staticIp = address.ip();
}
proxy.listen(proxyPort, proxyIp, function(err) {
console.log(chalk.black.bgWhite.bold('ffrk-proxy') + chalk.black.bgWhite(' ' + info.version + ' started'));
console.log('listening on: ' + chalk.green(proxyIp + ':' + proxyPort));
if (err) {
console.log(err, err.stack.split('\n'));
process.exit(1);
}
});
module.exports = ({
https,
host,
port,
expectedPort,
open,
isFirstBuild,
publicUrl
}) => {
const ip = address.ip()
const protocol = https ? 'https' : 'http'
const isUnspecifiedHost = host === '0.0.0.0' || host === '::'
const prettyHost = isUnspecifiedHost ? 'localhost' : host
const { heapUsed } = process.memoryUsage()
const urlPort = colors.bold(port)
const urlPath = publicUrl === '/' ? '' : url.resolve('/', publicUrl)
console.log()
console.log(
`Local: ${protocol}://${prettyHost}:${urlPort}${urlPath}`
)
console.log(`On Your Network: ${protocol}://${ip}:${urlPort}${urlPath}`)
console.log()
if (expectedPort && expectedPort !== port) {