fix: local server start error should not change to started state (#2052)

This commit is contained in:
Louis 2024-02-16 14:58:34 +07:00 committed by GitHub
parent 7fb61bf0fb
commit 6590ee7a6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 5 deletions

View File

@ -6,7 +6,6 @@ export const getSystemResourceInfo = async (): Promise<SystemResourceInfo> => {
const cpu = await physicalCpuCount()
const message = `[NITRO]::CPU informations - ${cpu}`
log(message)
logServer(message)
return {
numCpuPhysicalCore: cpu,

View File

@ -45,7 +45,7 @@ export interface ServerConfig {
* Function to start the server
* @param configs - Server configurations
*/
export const startServer = async (configs?: ServerConfig) => {
export const startServer = async (configs?: ServerConfig): Promise<boolean> => {
// Update server settings
isVerbose = configs?.isVerboseEnabled ?? true
hostSetting = configs?.host ?? JAN_API_HOST
@ -123,10 +123,12 @@ export const startServer = async (configs?: ServerConfig) => {
`Debug: JAN API listening at: http://${hostSetting}:${portSetting}`
)
})
return true
} catch (e) {
// Log any errors
if (isVerbose) logServer(`Error: ${e}`)
}
return false
}
/**

View File

@ -122,20 +122,20 @@ const LocalServerScreen = () => {
block
themes={serverEnabled ? 'danger' : 'primary'}
disabled={stateModel.loading || errorRangePort || !selectedModel}
onClick={() => {
onClick={async () => {
if (serverEnabled) {
window.core?.api?.stopServer()
setServerEnabled(false)
setLoadModelError(undefined)
} else {
startModel(String(selectedModel?.id))
window.core?.api?.startServer({
const isStarted = await window.core?.api?.startServer({
host,
port,
isCorsEnabled,
isVerboseEnabled,
})
setServerEnabled(true)
if (isStarted) setServerEnabled(true)
if (firstTimeVisitAPIServer) {
localStorage.setItem(FIRST_TIME_VISIT_API_SERVER, 'false')
setFirstTimeVisitAPIServer(false)