add api host setting

This commit is contained in:
josc146 2023-05-24 22:03:30 +08:00
parent 03a494e1f1
commit f439b3d382
8 changed files with 25 additions and 10 deletions

View File

@ -6,12 +6,12 @@ import (
"strconv" "strconv"
) )
func (a *App) StartServer(port int) (string, error) { func (a *App) StartServer(port int, host string) (string, error) {
python, err := GetPython() python, err := GetPython()
if err != nil { if err != nil {
return "", err return "", err
} }
return Cmd(python, "./backend-python/main.py", strconv.Itoa(port)) return Cmd(python, "./backend-python/main.py", strconv.Itoa(port), host)
} }
func (a *App) ConvertModel(modelPath string, strategy string, outPath string) (string, error) { func (a *App) ConvertModel(modelPath string, strategy string, outPath string) (string, error) {

View File

@ -64,5 +64,9 @@ def debug():
if __name__ == "__main__": if __name__ == "__main__":
uvicorn.run("main:app", port=8000 if len(sys.argv) == 1 else int(sys.argv[1])) uvicorn.run(
"main:app",
port=8000 if len(sys.argv) < 2 else int(sys.argv[1]),
host="127.0.0.1" if len(sys.argv) < 3 else sys.argv[2],
)
# debug() # debug()

View File

@ -115,5 +115,6 @@
"Explain Code": "代码解释", "Explain Code": "代码解释",
"Werewolf": "狼人杀", "Werewolf": "狼人杀",
"Blank": "空白", "Blank": "空白",
"The following is an epic science fiction masterpiece that is immortalized, with delicate descriptions and grand depictions of interstellar civilization wars.\nChapter 1.\n": "以下是不朽的科幻史诗巨著,描写细腻,刻画了宏大的星际文明战争。\n第一章\n" "The following is an epic science fiction masterpiece that is immortalized, with delicate descriptions and grand depictions of interstellar civilization wars.\nChapter 1.\n": "以下是不朽的科幻史诗巨著,描写细腻,刻画了宏大的星际文明战争。\n第一章\n",
"API Host": "API主机"
} }

View File

@ -110,7 +110,7 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
await exit(1000).catch(() => { await exit(1000).catch(() => {
}); });
StartServer(port); StartServer(port, commonStore.settings.host);
setTimeout(WindowShow, 1000); setTimeout(WindowShow, 1000);
let timeoutCount = 6; let timeoutCount = 6;

View File

@ -1,6 +1,6 @@
import React, { FC } from 'react'; import React, { FC } from 'react';
import { Page } from '../components/Page'; import { Page } from '../components/Page';
import { Dropdown, Option, Switch } from '@fluentui/react-components'; import { Dropdown, Input, Option, Switch } from '@fluentui/react-components';
import { Labeled } from '../components/Labeled'; import { Labeled } from '../components/Labeled';
import commonStore from '../stores/commonStore'; import commonStore from '../stores/commonStore';
import { observer } from 'mobx-react-lite'; import { observer } from 'mobx-react-lite';
@ -20,6 +20,7 @@ export type SettingsType = {
autoUpdatesCheck: boolean autoUpdatesCheck: boolean
giteeUpdatesSource: boolean giteeUpdatesSource: boolean
cnMirror: boolean cnMirror: boolean
host: string
} }
export const Settings: FC = observer(() => { export const Settings: FC = observer(() => {
@ -87,6 +88,14 @@ export const Settings: FC = observer(() => {
}} /> }} />
} /> } />
} }
<Labeled label={t('API Host')} flex spaceBetween content={
<Input value={commonStore.settings.host}
onChange={(e, data) => {
commonStore.setSettings({
host: data.value
});
}} />
} />
</div> </div>
} /> } />
); );

View File

@ -55,7 +55,8 @@ class CommonStore {
darkMode: !isSystemLightMode(), darkMode: !isSystemLightMode(),
autoUpdatesCheck: true, autoUpdatesCheck: true,
giteeUpdatesSource: getUserLanguage() === 'zh', giteeUpdatesSource: getUserLanguage() === 'zh',
cnMirror: getUserLanguage() === 'zh' cnMirror: getUserLanguage() === 'zh',
host: '127.0.0.1'
}; };
// about // about
about: AboutContent = manifest.about; about: AboutContent = manifest.about;

View File

@ -34,6 +34,6 @@ export function ReadJson(arg1:string):Promise<any>;
export function SaveJson(arg1:string,arg2:any):Promise<void>; export function SaveJson(arg1:string,arg2:any):Promise<void>;
export function StartServer(arg1:number):Promise<string>; export function StartServer(arg1:number,arg2:string):Promise<string>;
export function UpdateApp(arg1:string):Promise<boolean>; export function UpdateApp(arg1:string):Promise<boolean>;

View File

@ -66,8 +66,8 @@ export function SaveJson(arg1, arg2) {
return window['go']['backend_golang']['App']['SaveJson'](arg1, arg2); return window['go']['backend_golang']['App']['SaveJson'](arg1, arg2);
} }
export function StartServer(arg1) { export function StartServer(arg1, arg2) {
return window['go']['backend_golang']['App']['StartServer'](arg1); return window['go']['backend_golang']['App']['StartServer'](arg1, arg2);
} }
export function UpdateApp(arg1) { export function UpdateApp(arg1) {