Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
// 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,
module.exports = new Promise((resolve, reject) => {
portfinder.basePort = port
portfinder.getPortPromise()
.then(newPort => {
if (port !== newPort) {
console.log(`${port}端口被占用,开启新端口${newPort}`)
}
var server = app.listen(newPort, 'localhost')
// for 小程序的文件保存机制
require('webpack-dev-middleware-hard-disk')(compiler, {
publicPath: webpackConfig.output.publicPath,
quiet: true
})
resolve({
ready: readyPromise,
close: () => {
server.close()
}
})
export async function startServer(cfg, fileWatcher = chokidar.watch([])) {
const result = createServer(cfg, fileWatcher);
const { app } = result;
let { server } = result;
const port = typeof cfg.port === 'number' ? cfg.port : await portfinder.getPortPromise();
// cleanup after quit
function closeFileWatcher() {
if (fileWatcher) {
fileWatcher.close();
/* eslint-disable-next-line no-param-reassign */
fileWatcher = undefined;
}
}
server.addListener('close', closeFileWatcher);
function stopServer() {
if (server) {
server.close();
server = undefined;
private async ensureServerIsRunning(): Promise<{ port: number; token: string }> {
if (!this.port || !this.token) {
// Compute a usable port.
this.port = await portfinder.getPortPromise({ startPort: 9000, port: 9000 });
this.token = uuid();
// Import webpanel server dynamically so doesn't load in the main extension until we
// get to here.
// tslint:disable-next-line:no-require-imports
const webPanelServerModule = require('./webPanelServer') as typeof import('./webPanelServer');
// Start the server listening.
const webPanelServer = new webPanelServerModule.WebPanelServer(this.port, this.token, this.fs);
webPanelServer.start();
this.disposableRegistry.push(webPanelServer);
}
return { port: this.port, token: this.token };
}
}
before(() => {
const skill = new StateMachineApp({ views });
const adapter = new AlexaAdapter(skill);
server = createServer(adapter);
return portfinder.getPortPromise()
.then((_port) => {
port = _port;
server.listen(port, () => debug(`Listening on ${port}`));
});
});
async function start(projectDir, appName, env = 'prod') {
const config = getConfig(projectDir, appName, env);
if (config.type === 'web') {
const backendPath = path.join(config.distDir, 'backend.js');
if (!fs.pathExistsSync(backendPath)) {
exit(`Please run \`basys build${appName ? ` ${appName}` : ''}\` command first`);
}
const port = await portfinder.getPortPromise({host: config.host, port: config.port});
config.port = port;
config.backendPort = port;
await fs.ensureDir(config.distDir);
await fs.writeFile(path.join(config.distDir, 'config.json'), JSON.stringify({port}));
require(backendPath);
console.log(`Your application is available at http://${config.host}:${port}`);
}
return config;
}
isPortTaken(port).then((isAvailable) => {
if (isAvailable) {
runServer(port);
} else {
//get an unused open port in the system
console.log('Port '+port+' is already in use, Fetching new port...');
portfinder.getPortPromise()
.then((port) => {
runServer(port);
})
.catch((err) => {
console.log("Unable to start the server : "+err);
})
}
}).catch((err) => {
console.log(err);
function getRandomPort(host: string): Promise {
return portfinder.getPortPromise({ host, port: PORT_START });
}
export function scanFreePort(start: number = 2866, end: number = 2888): Promise {
return portfinder.getPortPromise({ port: start, stopPort: end });
}
static async create(client: TwitchClient, config: WebHookListenerConfig = {}) {
const listenerPort = config.port || (await portFinder.getPortPromise());
const reverseProxy = config.reverseProxy || {};
return new WebHookListener(
{
hostName: config.hostName || (await publicIp.v4()),
port: listenerPort,
ssl: config.ssl,
reverseProxy: {
port: reverseProxy.port || listenerPort,
ssl: reverseProxy.ssl === undefined ? !!config.ssl : reverseProxy.ssl,
pathPrefix: reverseProxy.pathPrefix || ''
},
hookValidity: config.hookValidity
},
client
);
}