mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 13:29:44 +00:00
failed to run on chrome browser with 'yarn web' (fix #84198)
This commit is contained in:
parent
ca2acdc8b6
commit
60387fd1bd
|
@ -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}`);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue