Skip to content

Commit a6710b3

Browse files
committed
Update isDevProxyRunning check to use API. Closes #218
Closes #218
1 parent 15d483a commit a6710b3

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
- Snippets: Updated all snippets to use new DLL name, `DevProxy.Plugins.dll`
2222
- Notification: Upgrade notification invokes package manager to upgrade Dev Proxy
2323
- Improved diagnostics range detection to ensure that they only appear againt the relevant code and don't overlap with ending quotes and commas
24+
- Detection: Changed isDevProxyRunning check to use Dev Proxy API instead of process detection
2425

2526
## [0.24.0] - 2025-06-04
2627

src/detect.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,27 @@ export const getOutdatedVersion = async (devProxyExe: string): Promise<string> =
4747
};
4848

4949
export const isDevProxyRunning = async (devProxyExe: string): Promise<boolean> => {
50-
const platform = os.platform();
51-
52-
if (platform === 'win32') {
53-
const processId = await executeCommand(`pwsh.exe -c "(Get-Process ${devProxyExe} -ErrorAction SilentlyContinue).Id"`);
54-
return processId.trim() !== '';
55-
};
56-
if (platform === 'darwin') {
57-
const processId = await executeCommand(`$SHELL -c "ps -e -o pid=,comm= | awk \'\\$2==\"${devProxyExe}\" {print \\$1}\'"`);
58-
return processId.trim() !== '';
59-
};
60-
if (platform === 'linux') {
61-
const processId = await executeCommand(`/bin/bash -c "ps -e -o pid=,comm= | awk \'\\$2==\"${devProxyExe}\" {print \\$1}\'"`);
62-
return processId.trim() !== '';
50+
try {
51+
// Get the API port from configuration
52+
const configuration = vscode.workspace.getConfiguration('dev-proxy-toolkit');
53+
const apiPort = configuration.get('apiPort') as number;
54+
55+
// Try to connect to the Dev Proxy API on the configured port
56+
const response = await fetch(`http://127.0.0.1:${apiPort}/proxy`, {
57+
method: 'GET',
58+
signal: AbortSignal.timeout(2000), // 2 second timeout
59+
});
60+
61+
// If we get any response (even an error), Dev Proxy is running
62+
return response.status >= 200 && response.status < 500;
63+
} catch (error) {
64+
// If the request fails (connection refused, timeout, etc.), Dev Proxy is not running
65+
return false;
6366
}
64-
return false;
6567
};
6668

6769
export const getDevProxyExe = (versionPreference: VersionPreference) => {
6870
return versionPreference === VersionPreference.Stable
6971
? VersionExeName.Stable
7072
: VersionExeName.Beta;
71-
};
73+
};

src/test/examples/devproxyrc.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
{
2-
"$schema": "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.24.0/rc.schema.json",
3-
"plugins": []
4-
}
2+
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.0/rc.schema.json",
3+
"plugins": [
4+
{
5+
"name": "LatencyPlugin",
6+
"enabled": true,
7+
"pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll"
8+
}
9+
],
10+
"urlsToWatch": ["https://jsonplaceholder.typicode.com/*"],
11+
"logLevel": "information",
12+
"newVersionNotification": "stable",
13+
"showSkipMessages": true
14+
}

0 commit comments

Comments
 (0)