diff --git a/scripts/code-web.js b/scripts/code-web.js index 27d538dc1c3899885f3cf90f5c9cd42129f90f29..123d8261a9ed8c50366266fd6b859c77e1c8372e 100755 --- a/scripts/code-web.js +++ b/scripts/code-web.js @@ -16,15 +16,25 @@ const opn = require('opn'); const minimist = require('vscode-minimist'); const APP_ROOT = path.dirname(__dirname); +const EXTENSIONS_ROOT = path.join(APP_ROOT, 'extensions'); const WEB_MAIN = path.join(APP_ROOT, 'src', 'vs', 'code', 'browser', 'workbench', 'workbench-dev.html'); -const PORT = 8080; const args = minimist(process.argv, { string: [ - 'no-launch' + 'no-launch', + 'scheme', + 'host' + ], + number: [ + 'port' ] }); +const PORT = args.port || process.env.PORT || 8080; +const SCHEME = args.scheme || process.env.VSCODE_SCHEME || 'http'; +const HOST = args.host || 'localhost'; +const AUTHORITY = process.env.VSCODE_AUTHORITY || `${HOST}:${PORT}`; + const server = http.createServer((req, res) => { const parsedUrl = url.parse(req.url, true); const pathname = parsedUrl.pathname; @@ -56,7 +66,7 @@ const server = http.createServer((req, res) => { }); server.listen(PORT, () => { - console.log(`Web UI available at http://localhost:${PORT}`); + console.log(`Web UI available at ${SCHEME}://${AUTHORITY}`); }); server.on('error', err => { @@ -87,7 +97,7 @@ function handleStaticExtension(req, res, parsedUrl) { // Strip `/static-extension/` from the path const relativeFilePath = path.normalize(decodeURIComponent(parsedUrl.pathname.substr('/static-extension/'.length))); - const filePath = path.join(APP_ROOT, 'extensions', relativeFilePath); + const filePath = path.join(EXTENSIONS_ROOT, relativeFilePath); return serveFile(req, res, filePath); } @@ -97,12 +107,12 @@ function handleStaticExtension(req, res, parsedUrl) { * @param {import('http').ServerResponse} res */ async function handleRoot(req, res) { - const extensionFolders = await util.promisify(fs.readdir)(path.join(APP_ROOT, 'extensions')); + const extensionFolders = await util.promisify(fs.readdir)(EXTENSIONS_ROOT); const mapExtensionFolderToExtensionPackageJSON = new Map(); await Promise.all(extensionFolders.map(async extensionFolder => { try { - const packageJSON = JSON.parse((await util.promisify(fs.readFile)(path.join(APP_ROOT, 'extensions', extensionFolder, 'package.json'))).toString()); + const packageJSON = JSON.parse((await util.promisify(fs.readFile)(path.join(EXTENSIONS_ROOT, extensionFolder, 'package.json'))).toString()); if (packageJSON.main && packageJSON.name !== 'vscode-api-tests') { return; // unsupported } @@ -125,7 +135,7 @@ async function handleRoot(req, res) { mapExtensionFolderToExtensionPackageJSON.forEach((packageJSON, extensionFolder) => { staticExtensions.push({ packageJSON, - extensionLocation: { scheme: 'http', authority: `localhost:${PORT}`, path: `/static-extension/${extensionFolder}` } + extensionLocation: { scheme: SCHEME, authority: AUTHORITY, path: `/static-extension/${extensionFolder}` } }); }); @@ -221,5 +231,5 @@ async function serveFile(req, res, filePath, responseHeaders = Object.create(nul } if (args.launch !== false) { - opn(`http://localhost:${PORT}`); + opn(`${SCHEME}://${HOST}:${PORT}`); }