Notes/src/routes/electron.ts
Panagiotis Papadopoulos 91c37fa235 chore(routes/electron): disable lint rule for specific line
in this case using "{}" allows all primitive values, which seems to be what is required here.
so let's disable the rule "@typescript-eslint/no-empty-object-type" for this line
2025-03-08 00:54:29 +01:00

59 lines
1.7 KiB
TypeScript

import { ipcMain } from "electron";
import type { Application } from "express";
interface Response {
statusCode: number;
getHeader: (name: string) => string;
setHeader: (name: string, value: string) => Response;
header: (name: string, value: string) => Response;
status: (statusCode: number) => Response;
send: (obj: {}) => void; // eslint-disable-line @typescript-eslint/no-empty-object-type
}
function init(app: Application) {
ipcMain.on("server-request", (event, arg) => {
const req = {
url: arg.url,
method: arg.method,
body: arg.data,
headers: arg.headers,
session: {
loggedIn: true
}
};
const respHeaders: Record<string, string> = {};
const res: Response = {
statusCode: 200,
getHeader: (name) => respHeaders[name],
setHeader: (name, value) => {
respHeaders[name] = value.toString();
return res;
},
header: (name, value) => {
respHeaders[name] = value.toString();
return res;
},
status: (statusCode) => {
res.statusCode = statusCode;
return res;
},
send: (obj) => {
event.sender.send("server-response", {
url: arg.url,
method: arg.method,
requestId: arg.requestId,
statusCode: res.statusCode,
headers: respHeaders,
body: obj
});
}
};
return app._router.handle(req, res, () => {});
});
}
export default init;