Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// serve pure static assets
const staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
app.use(staticPath, express.static('./static'))
const uri = config.dev.openBrowserUriHost === 'http://localhost:'? config.dev.openBrowserUriHost + port : config.dev.openBrowserUriHost
var _resolve
var _reject
var readyPromise = new Promise((resolve, reject) => {
_resolve = resolve
_reject = reject
})
var server
var portfinder = require('portfinder')
portfinder.basePort = port
console.log('> Starting dev server...')
devMiddleware.waitUntilValid(() => {
portfinder.getPort((err, port) => {
if (err) {
_reject(err)
}
process.env.PORT = port
var uri = config.dev.openBrowserUriHost === 'http://localhost:'? config.dev.openBrowserUriHost + port : config.dev.openBrowserUriHost
console.log('> Listening at ' + uri + '\n')
// when env is testing, don't need open it
if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
opn(uri)
}
server = app.listen(port)
_resolve()
test(`setup ${__filename}`, t => {
t.plan(1)
frockfile = JSON.parse(fs.readFileSync(path.join(__dirname, 'frockfile.json')))
portfinder.getPorts(3, (err, foundPorts) => {
if (err) {
t.fail(err)
}
ports = foundPorts
// mangle the found ports into the loaded frockfile
frockfile.servers[0].port = ports[0]
frockfile.servers[1].port = ports[1]
frockfile.sockets[0].port = ports[2]
frock = lib(frockfile, {pwd})
frock.run(err => {
if (err) {
t.fail(err)
before((done) => createInfos(5, (err, infos) => {
expect(err).to.not.exist()
getPorts(6, (err, ports) => {
expect(err).to.not.exist()
bootstrapPeer = infos[0]
tcpPeer1 = infos[1]
tcpPeer2 = infos[2]
wsPeer1 = infos[3]
wsPeer2 = infos[4]
// Setup the addresses of our nodes
bootstrapPeer.multiaddrs.add(`/ip4/0.0.0.0/tcp/${ports.shift()}`)
bootstrapPeer.multiaddrs.add(`/ip4/0.0.0.0/tcp/${ports.shift()}/ws`)
tcpPeer1.multiaddrs.add(`/ip4/0.0.0.0/tcp/${ports.shift()}`)
tcpPeer2.multiaddrs.add(`/ip4/0.0.0.0/tcp/${ports.shift()}`)
wsPeer1.multiaddrs.add(`/ip4/0.0.0.0/tcp/${ports.shift()}/ws`)
wsPeer2.multiaddrs.add(`/ip4/0.0.0.0/tcp/${ports.shift()}/ws`)
/* eslint-disable no-console, no-process-exit */
import 'colors';
import portfinder from 'portfinder';
import { exec } from 'child-process-promise';
// import ip from 'ip';
portfinder.basePort = 4000;
const SIGINT = 'SIGINT';
let processMap = {};
function output(prefix, message) {
let formattedMessage = message.toString().trim().split('\n')
.reduce((acc, line) => `${acc}${ acc !== '' ? '\n' : '' }${prefix} ${line}`, '');
console.log(formattedMessage);
}
function listen({stdout, stderr}, name) {
stdout.on('data', data => output(`[${name}] `.grey, data));
stderr.on('data', data => output(`[${name}] `.grey, data));
}
return;
})
.then(() => console.log('Shutdown: '.cyan + name.green))
.catch(err => {
if (catchExec(name, err)) {
// Restart if not explicitly shutdown
runCmd(name, cmd, options);
}
});
}
console.log('Starting docs in Development mode'.cyan);
process.on(SIGINT, shutdown);
portfinder.getPorts(2, {}, (portFinderErr, [docsPort, webpackPort]) => {
if (portFinderErr) {
console.log('Failed to acquire ports'.red);
process.exit(1);
}
// runCmd('webpack-dev-server', `nodemon --watch webpack --watch webpack.docs.js --exec webpack-dev-server -- --config webpack.docs.js --color --port ${webpackPort} --debug --hot --host ${ip.address()}`);
runCmd('webpack-dev-server', `nodemon --watch webpack --watch webpack.docs.js --exec webpack-dev-server -- --config webpack.docs.js --color --port ${webpackPort} --debug --hot --host 127.0.0.1`);
runCmd('docs-server', 'nodemon --watch docs --watch src --exec babel-node docs/server.js', {
env: {
PORT: docsPort,
WEBPACK_DEV_PORT: webpackPort,
...process.env
}
});
});
processMap[name] = childProcess;
})
.then(() => console.log('Shutdown: '.cyan + name.green))
.catch((err) => {
if (catchExec(name, err)) {
// Restart if not explicitly shutdown
runCmd(name, cmd, options);
}
});
}
console.log('Starting docs in Development mode'.cyan);
process.on(SIGINT, shutdown);
portfinder.getPorts(2, {}, (portFinderErr, [docsPort, webpackPort]) => {
if (portFinderErr) {
console.log('Failed to acquire ports'.red);
process.exit(1);
}
runCmd('webpack-dev-server', `nodemon --watch webpack --watch webpack.docs.js --exec webpack-dev-server -- --config webpack.docs.js --color --port ${webpackPort} --debug --hot --host ${ip.address()}`);
runCmd('docs-server', 'nodemon --watch docs --watch src --exec babel-node docs/server.js', {
env: {
PORT: docsPort,
WEBPACK_DEV_PORT: webpackPort,
...process.env,
},
});
});
// serve pure static assets
const staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
app.use(staticPath, express.static('./static'))
const uri = 'http://localhost:' + port
var _resolve
var _reject
var readyPromise = new Promise((resolve, reject) => {
_resolve = resolve
_reject = reject
})
var server
var portfinder = require('portfinder')
portfinder.basePort = port
console.log('> Starting dev server...')
devMiddleware.waitUntilValid(() => {
portfinder.getPort((err, port) => {
if (err) {
_reject(err)
}
process.env.PORT = port
var uri = 'http://localhost:' + port
console.log('> Listening at ' + uri + '\n')
// when env is testing, don't need open it
if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
opn(uri)
}
server = app.listen(port)
_resolve()
// serve static posts
app.use('/posts', express.static(__dirname + '/../dist/posts/'))
app.use('/feed.xml', express.static(__dirname + '/../dist/feed.xml'))
const uri = 'http://localhost:' + port
var _resolve
var _reject
var readyPromise = new Promise((resolve, reject) => {
_resolve = resolve
_reject = reject
})
var server
var portfinder = require('portfinder')
portfinder.basePort = port
console.log('> Starting dev server...')
devMiddleware.waitUntilValid(() => {
portfinder.getPort((err, port) => {
if (err) {
_reject(err)
}
process.env.PORT = port
var uri = 'http://localhost:' + port
console.log('> Listening at ' + uri + '\n')
// when env is testing, don't need open it
if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
opn(uri)
}
server = app.listen(port)
_resolve()
// 直接打开最新添加的项目,方便调试
let projectList = config.projectConfig.project
let lastedProjectIndex = Object.keys(projectList).length - 1
let lastedProjectUri = uri + '/' + config.projectConfig.staticRoot + '/html/' + Object.keys(projectList)[lastedProjectIndex] + '/index.html'
console.log(`lasted_project_uri => ${lastedProjectUri}`)
var _resolve
var _reject
var readyPromise = new Promise((resolve, reject) => {
_resolve = resolve
_reject = reject
})
var server
var portfinder = require('portfinder')
portfinder.basePort = port
console.log('> Starting dev server...')
devMiddleware.waitUntilValid(() => {
portfinder.getPort((err, port) => {
if (err) {
_reject(err)
}
process.env.PORT = port
console.log('> Listening at ' + uri + '\n')
// when env is testing, don't need open it
if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
opn(lastedProjectUri)
}
server = app.listen(port)
_resolve()
})
}
// entry arg
const entry = args._[0]
if (entry) {
webpackConfig.entry = {
app: api.resolve(entry)
}
}
// resolve server options
const useHttps = args.https || projectDevServerOptions.https || defaults.https
const protocol = useHttps ? 'https' : 'http'
const host = args.host || process.env.HOST || projectDevServerOptions.host || defaults.host
portfinder.basePort = args.port || process.env.PORT || projectDevServerOptions.port || defaults.port
const port = await portfinder.getPortPromise()
const rawPublicUrl = args.public || projectDevServerOptions.public
const publicUrl = rawPublicUrl
? /^[a-zA-Z]+:\/\//.test(rawPublicUrl)
? rawPublicUrl
: `${protocol}://${rawPublicUrl}`
: null
const urls = prepareURLs(
protocol,
host,
port,
isAbsoluteUrl(options.baseUrl) ? '/' : options.baseUrl
)
const proxySettings = prepareProxy(
projectDevServerOptions.proxy,