Skip to content

Commit

Permalink
chore: remove server functions from core package
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-menlo committed Dec 31, 2024
1 parent 8ae1e4a commit 1bb9d6c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 28 deletions.
25 changes: 0 additions & 25 deletions core/src/node/api/processors/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
}
}
7 changes: 4 additions & 3 deletions core/src/types/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ export enum NativeRoute {

quickAskSizeUpdated = 'quickAskSizeUpdated',
ackDeepLink = 'ackDeepLink',
factoryReset = 'factoryReset'
factoryReset = 'factoryReset',

startServer = 'startServer',
stopServer = 'stopServer',
}

/**
Expand All @@ -41,8 +44,6 @@ export enum AppRoute {
dirName = 'dirName',
isSubdirectory = 'isSubdirectory',
baseName = 'baseName',
startServer = 'startServer',
stopServer = 'stopServer',
log = 'log',
systemInformation = 'systemInformation',
showToast = 'showToast',
Expand Down
35 changes: 35 additions & 0 deletions electron/handlers/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
}
3 changes: 3 additions & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@
"run-script-os": "^1.1.6",
"typescript": "^5.3.3"
},
"bundleDependencies": [
"@fastify/swagger-ui"
],
"packageManager": "yarn@4.5.3"
}
1 change: 1 addition & 0 deletions server/rolldown.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default defineConfig([
resolve: {
extensions: ['.js', '.ts'],
},
external: ['@fastify/swagger-ui'],
platform: 'node',
},
])

0 comments on commit 1bb9d6c

Please sign in to comment.