chore: remove server functions from core package

This commit is contained in:
Louis 2024-12-31 19:20:20 +07:00
parent 8ae1e4a24a
commit 1bb9d6ce1f
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2
5 changed files with 43 additions and 28 deletions

View File

@ -44,11 +44,8 @@ export class App implements Processor {
/**
* Checks if the given path is a subdirectory of the given directory.
*
* @param _event - The IPC event object.
* @param from - The path to check.
* @param to - The directory to check against.
*
* @returns {Promise<boolean>} - A promise that resolves with the result.
*/
isSubdirectory(from: any, to: any) {
const rel = relative(from, to)
@ -79,26 +76,4 @@ export class App implements Processor {
async updateAppConfiguration(args: any) {
await updateAppConfiguration(args)
}
/**
* Start Jan API Server.
*/
async startServer(args?: any) {
const { startServer } = require('@janhq/server')
return startServer({
host: args?.host,
port: args?.port,
isCorsEnabled: args?.isCorsEnabled,
isVerboseEnabled: args?.isVerboseEnabled,
prefix: args?.prefix,
})
}
/**
* Stop Jan API Server.
*/
stopServer() {
const { stopServer } = require('@janhq/server')
return stopServer()
}
}

View File

@ -27,7 +27,10 @@ export enum NativeRoute {
quickAskSizeUpdated = 'quickAskSizeUpdated',
ackDeepLink = 'ackDeepLink',
factoryReset = 'factoryReset'
factoryReset = 'factoryReset',
startServer = 'startServer',
stopServer = 'stopServer',
}
/**
@ -41,8 +44,6 @@ export enum AppRoute {
dirName = 'dirName',
isSubdirectory = 'isSubdirectory',
baseName = 'baseName',
startServer = 'startServer',
stopServer = 'stopServer',
log = 'log',
systemInformation = 'systemInformation',
showToast = 'showToast',

View File

@ -277,4 +277,39 @@ export function handleAppIPCs() {
ModuleManager.instance.clearImportedModules()
return createUserSpace().then(migrate).then(setupExtensions)
})
/**
* Handles the "startServer" IPC message to start the Jan API server.
* Initializes and starts server with provided configuration options.
* @param _event - The IPC event object.
* @param args - Configuration object containing host, port, CORS settings etc.
* @returns Promise that resolves when server starts successfully
*/
ipcMain.handle(
NativeRoute.startServer,
async (_event, args): Promise<void> => {
const { startServer } = require('@janhq/server')
return startServer({
host: args?.host,
port: args?.port,
isCorsEnabled: args?.isCorsEnabled,
isVerboseEnabled: args?.isVerboseEnabled,
prefix: args?.prefix,
})
}
)
/**
* Handles the "stopServer" IPC message to stop the Jan API server.
* Gracefully shuts down the server instance.
* @param _event - The IPC event object
* @returns Promise that resolves when server stops successfully
*/
ipcMain.handle(NativeRoute.stopServer, async (_event): Promise<void> => {
/**
* Stop Jan API Server.
*/
const { stopServer } = require('@janhq/server')
return stopServer()
})
}

View File

@ -36,5 +36,8 @@
"run-script-os": "^1.1.6",
"typescript": "^5.3.3"
},
"bundleDependencies": [
"@fastify/swagger-ui"
],
"packageManager": "yarn@4.5.3"
}

View File

@ -12,6 +12,7 @@ export default defineConfig([
resolve: {
extensions: ['.js', '.ts'],
},
external: ['@fastify/swagger-ui'],
platform: 'node',
},
])