This repository was archived by the owner on Oct 18, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathapi.ts
More file actions
73 lines (66 loc) · 2.56 KB
/
api.ts
File metadata and controls
73 lines (66 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import express from "express";
import bodyParser from "body-parser";
import getPort from "get-port";
import middleware from "./api/middleware";
import clipboardRoutes from "./api/clipboard";
import appRoutes from "./api/app";
import screenRoutes from "./api/screen";
import dialogRoutes from "./api/dialog";
import debugRoutes from "./api/debug";
import broadcastingRoutes from "./api/broadcasting";
import systemRoutes from "./api/system";
import globalShortcutRoutes from "./api/globalShortcut";
import notificationRoutes from "./api/notification";
import dockRoutes from "./api/dock";
import menuRoutes from "./api/menu";
import menuBarRoutes from "./api/menuBar";
import windowRoutes from "./api/window";
import processRoutes from "./api/process";
import contextMenuRoutes from "./api/contextMenu";
import settingsRoutes from "./api/settings";
import shellRoutes from "./api/shell";
import progressBarRoutes from "./api/progressBar";
import powerMonitorRoutes from "./api/powerMonitor";
import { Server } from "net";
export interface APIProcess {
server: Server;
port: number;
}
async function startAPIServer(randomSecret: string): Promise<APIProcess> {
const port = await getPort({
port: getPort.makeRange(4000, 5000),
});
return new Promise((resolve, reject) => {
const httpServer = express();
httpServer.use(middleware(randomSecret));
httpServer.use(bodyParser.json());
httpServer.use("/api/clipboard", clipboardRoutes);
httpServer.use("/api/app", appRoutes);
httpServer.use("/api/screen", screenRoutes);
httpServer.use("/api/dialog", dialogRoutes);
httpServer.use("/api/system", systemRoutes);
httpServer.use("/api/global-shortcuts", globalShortcutRoutes);
httpServer.use("/api/notification", notificationRoutes);
httpServer.use("/api/dock", dockRoutes);
httpServer.use("/api/menu", menuRoutes);
httpServer.use("/api/window", windowRoutes);
httpServer.use("/api/process", processRoutes);
httpServer.use("/api/settings", settingsRoutes);
httpServer.use("/api/shell", shellRoutes);
httpServer.use("/api/context", contextMenuRoutes);
httpServer.use("/api/menu-bar", menuBarRoutes);
httpServer.use("/api/progress-bar", progressBarRoutes);
httpServer.use("/api/power-monitor", powerMonitorRoutes);
httpServer.use("/api/broadcast", broadcastingRoutes);
if (process.env.NODE_ENV === "development") {
httpServer.use("/api/debug", debugRoutes);
}
const server = httpServer.listen(port, () => {
resolve({
server,
port,
});
});
});
}
export default startAPIServer;