Menu

Our desktop app serves its own UI over HTTP, and 127.0.0.1 is the only auth on 32 routes
📰

Our desktop app serves its own UI over HTTP, and 127.0.0.1 is the only auth on 32 routes

DEV Community: node·Daniel Pertu·about 3 hours ago
#cCiWh2E8
#devtonodejs#devto#dev#port#window
Reading 0:00
15s threshold

Notifio is a desktop app that watches rental search pages and emails you when a new listing appears. It is an Electron app, so the obvious architecture is a main process, a preload script, a contextBridge surface and a pile of ipcMain.handle calls.

It is not built that way. The main process starts an Express server in-process, and the window is a browser pointed at it:

mainWindow . loadURL ( `http://localhost: ${ serverPort } ` );

Enter fullscreen mode

Exit fullscreen mode

The renderer does not know it is in Electron at all. It talks to its own origin:

// The renderer is served by the embedded Express server, so talk to it on the // same origin. This keeps things working if PORT is changed from the default. const BASE = typeof window !== " undefined " ? window . location . origin : " http://localhost:3000 " ;

Enter fullscreen mode

Exit fullscreen mode

ipcMain appears in exactly one file in the repository, and it belongs to the auto-reply recorder window.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.