From 1bb9d6ce1f3541935b85d274efe3f36f10721f1c Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 31 Dec 2024 19:20:20 +0700 Subject: [PATCH] chore: remove server functions from core package --- core/src/node/api/processors/app.ts | 25 --------------------- core/src/types/api/index.ts | 7 +++--- electron/handlers/native.ts | 35 +++++++++++++++++++++++++++++ server/package.json | 3 +++ server/rolldown.config.mjs | 1 + 5 files changed, 43 insertions(+), 28 deletions(-) diff --git a/core/src/node/api/processors/app.ts b/core/src/node/api/processors/app.ts index 96af8468e..d86e6265c 100644 --- a/core/src/node/api/processors/app.ts +++ b/core/src/node/api/processors/app.ts @@ -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} - 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() - } } diff --git a/core/src/types/api/index.ts b/core/src/types/api/index.ts index dc9afcb00..63b0eb10e 100644 --- a/core/src/types/api/index.ts +++ b/core/src/types/api/index.ts @@ -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', diff --git a/electron/handlers/native.ts b/electron/handlers/native.ts index 813231bd4..81a2fc7f5 100644 --- a/electron/handlers/native.ts +++ b/electron/handlers/native.ts @@ -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 => { + 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 => { + /** + * Stop Jan API Server. + */ + const { stopServer } = require('@janhq/server') + return stopServer() + }) } diff --git a/server/package.json b/server/package.json index 3f2c54a7b..fed08a3e7 100644 --- a/server/package.json +++ b/server/package.json @@ -36,5 +36,8 @@ "run-script-os": "^1.1.6", "typescript": "^5.3.3" }, + "bundleDependencies": [ + "@fastify/swagger-ui" + ], "packageManager": "yarn@4.5.3" } diff --git a/server/rolldown.config.mjs b/server/rolldown.config.mjs index 3f6acae63..c74655577 100644 --- a/server/rolldown.config.mjs +++ b/server/rolldown.config.mjs @@ -12,6 +12,7 @@ export default defineConfig([ resolve: { extensions: ['.js', '.ts'], }, + external: ['@fastify/swagger-ui'], platform: 'node', }, ])