Skip to content

Commit

Permalink
feat(es-dev-server): allow opening on full URL
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsDenBakker authored and daKmoR committed Dec 2, 2019
1 parent 90cdeaf commit 6d47e56
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/es-dev-server/package.json
Expand Up @@ -103,6 +103,7 @@
"@types/node-fetch": "^2.3.7",
"@types/puppeteer": "^2.0.0",
"@types/request": "^2.48.1",
"@types/whatwg-url": "^6.4.0",
"abort-controller": "^3.0.0",
"chai": "^4.2.0",
"koa-proxies": "^0.8.1",
Expand Down
5 changes: 0 additions & 5 deletions packages/es-dev-server/src/config.js
Expand Up @@ -192,11 +192,6 @@ export function createConfig(config) {
openPath = basePath ? `${basePath}/` : '/';
}

// make sure path properly starts a /
if (!openPath.startsWith('/')) {
openPath = `/${openPath}`;
}

return {
appIndex,
appIndexDir,
Expand Down
19 changes: 18 additions & 1 deletion packages/es-dev-server/src/start-server.js
@@ -1,8 +1,17 @@
import opn from 'opn';
import chokidar from 'chokidar';
import portfinder from 'portfinder';
import { URL } from 'url';
import { createServer } from './create-server.js';

function isValidURL(str) {
try {
return !!new URL(str);
} catch (error) {
return false;
}
}

/** @param {import('./config.js').InternalConfig} cfg */
export async function startServer(cfg, fileWatcher = chokidar.watch([])) {
const result = createServer(cfg, fileWatcher);
Expand Down Expand Up @@ -68,7 +77,15 @@ export async function startServer(cfg, fileWatcher = chokidar.watch([])) {
}

if (cfg.openBrowser) {
opn(`http${cfg.http2 ? 's' : ''}://${prettyHost}:${port}${cfg.openPath}`);
const openPath = (() => {
if (isValidURL(cfg.openPath)) {
return cfg.openPath;
}

return new URL(cfg.openPath, `http${cfg.http2 ? 's' : ''}://${prettyHost}:${port}`).href;
})();

opn(openPath);
}

resolve();
Expand Down
15 changes: 11 additions & 4 deletions yarn.lock
Expand Up @@ -2106,16 +2106,16 @@
standard-version "^7.0.1"

"@open-wc/testing-karma-bs@file:./packages/testing-karma-bs":
version "1.3.4"
version "1.3.6"
dependencies:
"@open-wc/testing-karma" "^3.2.4"
"@open-wc/testing-karma" "^3.2.6"
"@types/node" "^11.13.0"
karma-browserstack-launcher "^1.0.0"

"@open-wc/testing-karma@file:./packages/testing-karma":
version "3.2.4"
version "3.2.6"
dependencies:
"@open-wc/karma-esm" "^2.10.4"
"@open-wc/karma-esm" "^2.10.6"
axe-core "^3.3.1"
karma "^4.1.0"
karma-chrome-launcher "^2.0.0"
Expand Down Expand Up @@ -2653,6 +2653,13 @@
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.3.tgz#9c088679876f374eb5983f150d4787aa6fb32d7e"
integrity sha512-FvUupuM3rlRsRtCN+fDudtmytGO6iHJuuRKS1Ss0pG5z8oX0diNEw94UEL7hgDbpN94rgaK5R7sWm6RrSkZuAQ==

"@types/whatwg-url@^6.4.0":
version "6.4.0"
resolved "https://registry.yarnpkg.com/@types/whatwg-url/-/whatwg-url-6.4.0.tgz#1e59b8c64bc0dbdf66d037cf8449d1c3d5270237"
integrity sha512-tonhlcbQ2eho09am6RHnHOgvtDfDYINd5rgxD+2YSkKENooVCFsWizJz139MQW/PV8FfClyKrNe9ZbdHrSCxGg==
dependencies:
"@types/node" "*"

"@vue/babel-helper-vue-jsx-merge-props@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@vue/babel-helper-vue-jsx-merge-props/-/babel-helper-vue-jsx-merge-props-1.0.0.tgz#048fe579958da408fb7a8b2a3ec050b50a661040"
Expand Down

0 comments on commit 6d47e56

Please sign in to comment.