feat(gpt-runner-vscode): add public ip support when open in browser
This commit is contained in:
@@ -58,17 +58,20 @@
|
||||
"peerDependencies": {
|
||||
"debug": "*",
|
||||
"find-free-ports": "*",
|
||||
"ip": "*",
|
||||
"minimatch": "*",
|
||||
"zod": "*"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": "^4.3.4",
|
||||
"find-free-ports": "^3.1.1",
|
||||
"ip": "^1.1.8",
|
||||
"minimatch": "^9.0.1",
|
||||
"zod": "^3.21.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^4.17.17",
|
||||
"@types/ip": "^1.1.0",
|
||||
"express": "^4.18.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import open from 'open'
|
||||
import fp from 'find-free-ports'
|
||||
import ip from 'ip'
|
||||
|
||||
export interface OpenInBrowserProps {
|
||||
url: string
|
||||
@@ -35,3 +36,8 @@ export async function getPort(props: GetPortProps): Promise<number> {
|
||||
|
||||
return freePort
|
||||
}
|
||||
|
||||
// return 192.168.xxx.xxx or 127.0.0.1
|
||||
export function getLocalHostname() {
|
||||
return ip.address('public', 'ipv4')
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ export async function registerOpenInBrowser(
|
||||
|
||||
disposable = vscode.commands.registerCommand(Commands.OpenInBrowser, () => {
|
||||
openInBrowser({
|
||||
url: `${getServerBaseUrl()}/#/chat?rootPath=${cwd}`,
|
||||
url: `${getServerBaseUrl(true)}/#/chat?rootPath=${cwd}`,
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as vscode from 'vscode'
|
||||
import { getLocalHostname } from '@nicepkg/gpt-runner-shared/node'
|
||||
import { EXT_NAME } from './constant'
|
||||
import { state } from './state'
|
||||
|
||||
@@ -41,6 +42,7 @@ export function createHash() {
|
||||
return text
|
||||
}
|
||||
|
||||
export function getServerBaseUrl() {
|
||||
return `http://localhost:${state.serverPort || 3003}`
|
||||
export function getServerBaseUrl(localIp = false) {
|
||||
const hostname = localIp ? getLocalHostname() : 'localhost'
|
||||
return `http://${hostname}:${state.serverPort || 3003}`
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ export interface GlobalConfig {
|
||||
window.__DEFAULT_GLOBAL_CONFIG__ = {
|
||||
rootPath: getSearchParams('rootPath') || '/Users/yangxiaoming/Documents/codes/gpt-runner',
|
||||
initialRoutePath: '/',
|
||||
serverBaseUrl: 'http://localhost:3003',
|
||||
serverBaseUrl: '',
|
||||
showDiffCodesBtn: false,
|
||||
showInsertCodesBtn: false,
|
||||
}
|
||||
|
||||
16
pnpm-lock.yaml
generated
16
pnpm-lock.yaml
generated
@@ -205,6 +205,9 @@ importers:
|
||||
find-free-ports:
|
||||
specifier: ^3.1.1
|
||||
version: 3.1.1
|
||||
ip:
|
||||
specifier: ^1.1.8
|
||||
version: 1.1.8
|
||||
minimatch:
|
||||
specifier: ^9.0.1
|
||||
version: 9.0.1
|
||||
@@ -215,6 +218,9 @@ importers:
|
||||
'@types/express':
|
||||
specifier: ^4.17.17
|
||||
version: 4.17.17
|
||||
'@types/ip':
|
||||
specifier: ^1.1.0
|
||||
version: 1.1.0
|
||||
express:
|
||||
specifier: ^4.18.2
|
||||
version: 4.18.2
|
||||
@@ -2544,6 +2550,12 @@ packages:
|
||||
'@types/unist': 2.0.6
|
||||
dev: false
|
||||
|
||||
/@types/ip@1.1.0:
|
||||
resolution: {integrity: sha512-dwNe8gOoF70VdL6WJBwVHtQmAX4RMd62M+mAB9HQFjG1/qiCLM/meRy95Pd14FYBbEDwCq7jgJs89cHpLBu4HQ==}
|
||||
dependencies:
|
||||
'@types/node': 18.16.9
|
||||
dev: true
|
||||
|
||||
/@types/js-cookie@2.2.7:
|
||||
resolution: {integrity: sha512-aLkWa0C0vO5b4Sr798E26QgOkss68Un0bLjs7u9qxzPT5CG+8DuNTffWES58YzJs3hrVAOs1wonycqEBqNJubA==}
|
||||
dev: false
|
||||
@@ -5886,6 +5898,10 @@ packages:
|
||||
side-channel: 1.0.4
|
||||
dev: true
|
||||
|
||||
/ip@1.1.8:
|
||||
resolution: {integrity: sha512-PuExPYUiu6qMBQb4l06ecm6T6ujzhmh+MeJcW9wa89PoAz5pvd4zPgN5WJV104mb6S2T1AwNIAaB70JNrLQWhg==}
|
||||
dev: false
|
||||
|
||||
/ip@2.0.0:
|
||||
resolution: {integrity: sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ==}
|
||||
dev: true
|
||||
|
||||
Reference in New Issue
Block a user