From 629518b69fbb33e7285535e36239595076dddb2e Mon Sep 17 00:00:00 2001 From: Benjamin Viney Date: Sun, 18 Feb 2024 19:58:56 +1030 Subject: [PATCH 1/4] Allow development on linux --- package-lock.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 7d8c18d..3cd1057 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2225,7 +2225,8 @@ "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", "hasInstallScript": true, "os": [ - "darwin" + "darwin", + "linux" ], "engines": { "node": "^8.16.0 || ^10.6.0 || >=11.0.0" From cc693165a3a5b6c753258919618b19d6b2ec41a3 Mon Sep 17 00:00:00 2001 From: Benjamin Viney Date: Sun, 18 Feb 2024 21:46:53 +1030 Subject: [PATCH 2/4] Add serverRoot option and autoconfigure if using a non-desktop appHost --- package.json | 5 +++++ src/extension.ts | 17 +++++++++++++++++ src/helpers.ts | 2 ++ 3 files changed, 24 insertions(+) diff --git a/package.json b/package.json index 2fd131a..918b18d 100644 --- a/package.json +++ b/package.json @@ -151,6 +151,11 @@ "default": "", "markdownDescription": "Absolute path to php.ini file. `string`" }, + "fiveServer.serverRoot": { + "type": "string", + "default": "AUTO", + "markdownDescription": "Manually set the server root. (Useful if the server is behind a reverse proxy) `string`\n\r*Server root is automatically set to be blank if running on desktop and \"/proxy/{PORT}/\" if on web*" + }, "fiveServer.host": { "type": "string", "default": "0.0.0.0", diff --git a/src/extension.ts b/src/extension.ts index 754fc94..07423c7 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -20,6 +20,7 @@ let pty: PTY; let activeFileName = ""; let root: string = ""; let _root: string | null = null; +let serverRoot: string = "ERROR"; let workspace: string | undefined; let rootAbsolute: string; let config: LiveServerParams = {}; @@ -111,6 +112,15 @@ const shouldInjectBody = () => { return false; }; +function guessServerRoot() { + // Auto set serverRoot based on appHost + if (config.serverRoot === "AUTO") { + serverRoot = "/"; + if (vscode.env.appHost !== "desktop") + serverRoot = "/proxy/" + config.port ?? "5500" + "/"; + } +} + export function activate(context: vscode.ExtensionContext) { context.workspaceState.update(state, "off"); @@ -268,6 +278,8 @@ export function activate(context: vscode.ExtensionContext) { // get configFile for "root, injectBody and highlight" config = { ...config, ...(await getConfigFile(true, workspace)) }; + guessServerRoot(); + if (_root) root = _root; else if (config && config.root) root = config.root; else root = ""; @@ -303,6 +315,7 @@ export function activate(context: vscode.ExtensionContext) { injectBody: shouldInjectBody(), open: config.open !== undefined ? config.open : file, root, + serverRoot, workspace, _cli: true, }); @@ -322,6 +335,7 @@ export function activate(context: vscode.ExtensionContext) { injectBody: shouldInjectBody(), open: config.open !== undefined ? config.open : file, root, + serverRoot, workspace, _cli: true, }); @@ -348,11 +362,14 @@ export function activate(context: vscode.ExtensionContext) { const file = basename(fileName); const root = fileName.replace(file, ""); + guessServerRoot(); + // start a simple server await fiveServer.start({ ...config, injectBody: shouldInjectBody(), root, + serverRoot, open: file, }); } diff --git a/src/helpers.ts b/src/helpers.ts index 63e9f3b..8bcde32 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -33,6 +33,7 @@ export const assignVSCodeConfiguration = () => { const navigate = getConfig("navigate"); const php = getConfig("php.executable"); const phpIni = getConfig("php.ini"); + const serverRoot = getConfig("serverRoot"); const host = getConfig("host"); const port = getConfig("port"); const injectBody = getConfig("injectBody"); @@ -44,6 +45,7 @@ export const assignVSCodeConfiguration = () => { navigate, php, phpIni, + serverRoot, host, port, injectBody, From 13b4426b2a0c936720d2d7fa3b187124345d012f Mon Sep 17 00:00:00 2001 From: Benjamin Viney Date: Sun, 18 Feb 2024 22:29:56 +1030 Subject: [PATCH 3/4] Rename serverRoot to baseURL --- package.json | 6 +++--- src/extension.ts | 22 +++++++++++----------- src/helpers.ts | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 918b18d..63a0dd5 100644 --- a/package.json +++ b/package.json @@ -151,10 +151,10 @@ "default": "", "markdownDescription": "Absolute path to php.ini file. `string`" }, - "fiveServer.serverRoot": { + "fiveServer.baseURL": { "type": "string", - "default": "AUTO", - "markdownDescription": "Manually set the server root. (Useful if the server is behind a reverse proxy) `string`\n\r*Server root is automatically set to be blank if running on desktop and \"/proxy/{PORT}/\" if on web*" + "default": "/", + "markdownDescription": "Manually set the baseURL of the server. (Useful if the server is behind a reverse proxy) `string`\n\r*If set to 'AUTO' server root will automatically be set to \"/\" if running on desktop and \"/proxy/{PORT}/\" if on web*" }, "fiveServer.host": { "type": "string", diff --git a/src/extension.ts b/src/extension.ts index 07423c7..af4d541 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -20,7 +20,7 @@ let pty: PTY; let activeFileName = ""; let root: string = ""; let _root: string | null = null; -let serverRoot: string = "ERROR"; +let baseURL: string = "ERROR"; let workspace: string | undefined; let rootAbsolute: string; let config: LiveServerParams = {}; @@ -112,12 +112,12 @@ const shouldInjectBody = () => { return false; }; -function guessServerRoot() { - // Auto set serverRoot based on appHost - if (config.serverRoot === "AUTO") { - serverRoot = "/"; +function autoSetBaseURL() { + // Auto set baseURL based on appHost + if (config.baseURL === "AUTO") { + baseURL = "/"; if (vscode.env.appHost !== "desktop") - serverRoot = "/proxy/" + config.port ?? "5500" + "/"; + baseURL = "/proxy/" + config.port ?? "5500" + "/"; } } @@ -278,7 +278,7 @@ export function activate(context: vscode.ExtensionContext) { // get configFile for "root, injectBody and highlight" config = { ...config, ...(await getConfigFile(true, workspace)) }; - guessServerRoot(); + autoSetBaseURL(); if (_root) root = _root; else if (config && config.root) root = config.root; @@ -315,7 +315,7 @@ export function activate(context: vscode.ExtensionContext) { injectBody: shouldInjectBody(), open: config.open !== undefined ? config.open : file, root, - serverRoot, + baseURL, workspace, _cli: true, }); @@ -335,7 +335,7 @@ export function activate(context: vscode.ExtensionContext) { injectBody: shouldInjectBody(), open: config.open !== undefined ? config.open : file, root, - serverRoot, + baseURL, workspace, _cli: true, }); @@ -362,14 +362,14 @@ export function activate(context: vscode.ExtensionContext) { const file = basename(fileName); const root = fileName.replace(file, ""); - guessServerRoot(); + autoSetBaseURL(); // start a simple server await fiveServer.start({ ...config, injectBody: shouldInjectBody(), root, - serverRoot, + baseURL, open: file, }); } diff --git a/src/helpers.ts b/src/helpers.ts index 8bcde32..5208926 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -33,7 +33,7 @@ export const assignVSCodeConfiguration = () => { const navigate = getConfig("navigate"); const php = getConfig("php.executable"); const phpIni = getConfig("php.ini"); - const serverRoot = getConfig("serverRoot"); + const baseURL = getConfig("baseURL"); const host = getConfig("host"); const port = getConfig("port"); const injectBody = getConfig("injectBody"); @@ -45,7 +45,7 @@ export const assignVSCodeConfiguration = () => { navigate, php, phpIni, - serverRoot, + baseURL, host, port, injectBody, From c8ff154dd8cf9c56c32af91877635c7c8cd9424a Mon Sep 17 00:00:00 2001 From: Benjamin Viney Date: Sun, 18 Feb 2024 23:32:16 +1030 Subject: [PATCH 4/4] Improve autoSetBaseURL --- src/extension.ts | 16 +++++++++++----- src/test/runTest.ts | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index af4d541..725b5c4 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -20,7 +20,7 @@ let pty: PTY; let activeFileName = ""; let root: string = ""; let _root: string | null = null; -let baseURL: string = "ERROR"; +let baseURL: string = "NULL"; let workspace: string | undefined; let rootAbsolute: string; let config: LiveServerParams = {}; @@ -114,11 +114,17 @@ const shouldInjectBody = () => { function autoSetBaseURL() { // Auto set baseURL based on appHost - if (config.baseURL === "AUTO") { - baseURL = "/"; - if (vscode.env.appHost !== "desktop") - baseURL = "/proxy/" + config.port ?? "5500" + "/"; + if (config.baseURL !== "AUTO") { + if (config.baseURL) baseURL = config.baseURL; + return; } + + if (vscode.env.appHost !== "desktop") { + baseURL = "/proxy/" + config.port ?? "5500" + "/"; + return; + } + + baseURL = "/"; } export function activate(context: vscode.ExtensionContext) { diff --git a/src/test/runTest.ts b/src/test/runTest.ts index 300c9d5..6ec5744 100644 --- a/src/test/runTest.ts +++ b/src/test/runTest.ts @@ -38,7 +38,7 @@ async function main() { { encoding: "utf-8", stdio: "inherit", - } + }, ); // Run the extension test