Skip to content

Commit

Permalink
refactor(seeder): expose express urls object (#3995)
Browse files Browse the repository at this point in the history
  • Loading branch information
moonlitgrace authored Aug 16, 2024
1 parent b2a5b2d commit 1a0b6b1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
7 changes: 6 additions & 1 deletion seeder/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ app.whenReady().then(async () => {
})
.postMessage("");

ipcMain.handle("get-express-port", () => express_port);
const EXPRESS_URLS = {
shiinobi_healthcheck: `http://localhost:${express_port}/shiinobi-healthcheck`,
staff: `http://localhost:${express_port}/staff`
};

ipcMain.handle("get-express-urls", () => EXPRESS_URLS);

await createWindow();

Expand Down
5 changes: 4 additions & 1 deletion seeder/src/preload/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ declare global {
electron: ElectronAPI;
api: {
get_app_version: () => Promise<string>;
get_express_port: () => Promise<string>;
get_express_urls: () => Promise<{
shiinobi_healthcheck: string;
staff: string;
}>;
// Shiinobi
[key in typeof SHIINOBI_COMMANDS[number]]: (...args: any[]) => Promise<object>;
};
Expand Down
2 changes: 1 addition & 1 deletion seeder/src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { COMMANDS as SHIINOBI_COMMANDS } from "$interfaces/shiinobi";
// Custom APIs for renderer
const api = {
get_app_version: () => ipcRenderer.invoke("get-app-version"),
get_express_port: () => ipcRenderer.invoke("get-express-port")
get_express_urls: () => ipcRenderer.invoke("get-express-urls")
};

SHIINOBI_COMMANDS.forEach((item) => {
Expand Down
4 changes: 1 addition & 3 deletions seeder/src/renderer/constants/urls.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
const EXPRESS_PORT = await window.api.get_express_port();

export const EXPRESS_API_URL = `http://localhost:${EXPRESS_PORT}/`;
export const EXPRESS_URLS = await window.api.get_express_urls();
4 changes: 2 additions & 2 deletions seeder/src/renderer/routes/staff/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import CommandInitializer from "@components/CommandInitializer";
import { Component } from "solid-js";
import { diffWords } from "diff";
import RenderDiff from "@components/RenderDiff";
import { EXPRESS_API_URL } from "@constants/urls";
import { EXPRESS_URLS } from "@constants/urls";

// MOCK data
const staff_db = {
Expand Down Expand Up @@ -36,7 +36,7 @@ const Staff: Component = () => {
console.log(e.detail);
};

console.log(EXPRESS_API_URL);
console.log(EXPRESS_URLS.staff);

const diff = {
name: diffWords(staff_db.name, staff_mal.name),
Expand Down

0 comments on commit 1a0b6b1

Please sign in to comment.