Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to set a base URL to allow proxying #51

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@
"default": "",
"markdownDescription": "Absolute path to php.ini file. `string`"
},
"fiveServer.baseURL": {
"type": "string",
"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",
"default": "0.0.0.0",
Expand Down
23 changes: 23 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
let activeFileName = "";
let root: string = "";
let _root: string | null = null;
let baseURL: string = "NULL";
let workspace: string | undefined;
let rootAbsolute: string;
let config: LiveServerParams = {};
Expand Down Expand Up @@ -111,6 +112,21 @@
return false;
};

function autoSetBaseURL() {
// Auto set baseURL based on appHost
if (config.baseURL !== "AUTO") {

Check failure on line 117 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Property 'baseURL' does not exist on type 'LiveServerParams'.

Check failure on line 117 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Property 'baseURL' does not exist on type 'LiveServerParams'.

Check failure on line 117 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Property 'baseURL' does not exist on type 'LiveServerParams'.
if (config.baseURL) baseURL = config.baseURL;

Check failure on line 118 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Property 'baseURL' does not exist on type 'LiveServerParams'.

Check failure on line 118 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Property 'baseURL' does not exist on type 'LiveServerParams'.

Check failure on line 118 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Property 'baseURL' does not exist on type 'LiveServerParams'.

Check failure on line 118 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Property 'baseURL' does not exist on type 'LiveServerParams'.

Check failure on line 118 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Property 'baseURL' does not exist on type 'LiveServerParams'.

Check failure on line 118 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Property 'baseURL' does not exist on type 'LiveServerParams'.
return;
}

if (vscode.env.appHost !== "desktop") {
baseURL = "/proxy/" + config.port ?? "5500" + "/";
return;
}

baseURL = "/";
}

export function activate(context: vscode.ExtensionContext) {
context.workspaceState.update(state, "off");

Expand Down Expand Up @@ -268,6 +284,8 @@
// get configFile for "root, injectBody and highlight"
config = { ...config, ...(await getConfigFile(true, workspace)) };

autoSetBaseURL();

if (_root) root = _root;
else if (config && config.root) root = config.root;
else root = "";
Expand Down Expand Up @@ -303,6 +321,7 @@
injectBody: shouldInjectBody(),
open: config.open !== undefined ? config.open : file,
root,
baseURL,

Check failure on line 324 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Argument of type '{ injectBody: boolean; open: string | boolean | string[] | null; root: string; baseURL: string; workspace: string; _cli: true; browser?: string | string[] | undefined; cache?: boolean | undefined; ... 25 more ...; spa?: boolean | undefined; }' is not assignable to parameter of type 'LiveServerParams'.

Check failure on line 324 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Argument of type '{ injectBody: boolean; open: string | boolean | string[] | null; root: string; baseURL: string; workspace: string; _cli: true; browser?: string | string[] | undefined; cache?: boolean | undefined; ... 25 more ...; spa?: boolean | undefined; }' is not assignable to parameter of type 'LiveServerParams'.

Check failure on line 324 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Argument of type '{ injectBody: boolean; open: string | boolean | string[] | null; root: string; baseURL: string; workspace: string; _cli: true; browser?: string | string[] | undefined; cache?: boolean | undefined; ... 25 more ...; spa?: boolean | undefined; }' is not assignable to parameter of type 'LiveServerParams'.
workspace,
_cli: true,
});
Expand All @@ -322,6 +341,7 @@
injectBody: shouldInjectBody(),
open: config.open !== undefined ? config.open : file,
root,
baseURL,

Check failure on line 344 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Argument of type '{ injectBody: boolean; open: string | boolean | string[] | null; root: string; baseURL: string; workspace: string; _cli: true; browser?: string | string[] | undefined; cache?: boolean | undefined; ... 25 more ...; spa?: boolean | undefined; }' is not assignable to parameter of type 'LiveServerParams'.

Check failure on line 344 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Argument of type '{ injectBody: boolean; open: string | boolean | string[] | null; root: string; baseURL: string; workspace: string; _cli: true; browser?: string | string[] | undefined; cache?: boolean | undefined; ... 25 more ...; spa?: boolean | undefined; }' is not assignable to parameter of type 'LiveServerParams'.

Check failure on line 344 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Argument of type '{ injectBody: boolean; open: string | boolean | string[] | null; root: string; baseURL: string; workspace: string; _cli: true; browser?: string | string[] | undefined; cache?: boolean | undefined; ... 25 more ...; spa?: boolean | undefined; }' is not assignable to parameter of type 'LiveServerParams'.
workspace,
_cli: true,
});
Expand All @@ -348,11 +368,14 @@
const file = basename(fileName);
const root = fileName.replace(file, "");

autoSetBaseURL();

// start a simple server
await fiveServer.start({
...config,
injectBody: shouldInjectBody(),
root,
baseURL,

Check failure on line 378 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Argument of type '{ injectBody: boolean; root: string; baseURL: string; open: string; browser?: string | string[] | undefined; cache?: boolean | undefined; configFile?: string | boolean | undefined; cors?: boolean | undefined; ... 25 more ...; _cli?: boolean | undefined; }' is not assignable to parameter of type 'LiveServerParams'.

Check failure on line 378 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Argument of type '{ injectBody: boolean; root: string; baseURL: string; open: string; browser?: string | string[] | undefined; cache?: boolean | undefined; configFile?: string | boolean | undefined; cors?: boolean | undefined; ... 25 more ...; _cli?: boolean | undefined; }' is not assignable to parameter of type 'LiveServerParams'.

Check failure on line 378 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Argument of type '{ injectBody: boolean; root: string; baseURL: string; open: string; browser?: string | string[] | undefined; cache?: boolean | undefined; configFile?: string | boolean | undefined; cors?: boolean | undefined; ... 25 more ...; _cli?: boolean | undefined; }' is not assignable to parameter of type 'LiveServerParams'.
open: file,
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const assignVSCodeConfiguration = () => {
const navigate = <boolean>getConfig("navigate");
const php = <string>getConfig("php.executable");
const phpIni = <string>getConfig("php.ini");
const baseURL = <string>getConfig("baseURL");
const host = <string>getConfig("host");
const port = <number>getConfig("port");
const injectBody = <boolean>getConfig("injectBody");
Expand All @@ -44,6 +45,7 @@ export const assignVSCodeConfiguration = () => {
navigate,
php,
phpIni,
baseURL,
host,
port,
injectBody,
Expand Down
2 changes: 1 addition & 1 deletion src/test/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function main() {
{
encoding: "utf-8",
stdio: "inherit",
}
},
);

// Run the extension test
Expand Down
Loading