Skip to content

Commit

Permalink
feat: add devServerUrl property to createElectronRouter for enhanced …
Browse files Browse the repository at this point in the history
…flexibility
  • Loading branch information
daltonmenezes committed Jan 22, 2025
1 parent fb2038d commit 986f6f8
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions packages/electron-router-dom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ export function createElectronRouter<
const T extends {
/**
* @description The port where the dev server is running.
* Only necessary if you are not using the devServerUrl property and you are not using the default port.
* @default 3000
*/
port?: number

/**
* @description The URL of the dev server is running.
* If not provided, it will use the default URL: `http://localhost:${port}`
*/
devServerUrl?: string

/**
* @description The types definition for the router
*/
Expand All @@ -50,7 +57,7 @@ export function createElectronRouter<
queryKeys?: string[]
}
},
>({ types, port = defaults.port }: ElectronRouterOutput<T>) {
>({ types, devServerUrl, port = defaults.port }: ElectronRouterOutput<T>) {
type Types = NonNullable<T['types']>
type IsStrictMode = Types['strict'] extends boolean ? Types['strict'] : true

Expand Down Expand Up @@ -93,6 +100,14 @@ export function createElectronRouter<
*/
port?: number

/**
* @description The path to dev server URL.
* Recommended for HRM or cases you need full control over the URL.
* If not provided, it will use the default URL: `http://localhost:${port}`
* or the one defined in **createElectronRouter** settings.
*/
devServerUrl?: string

/**
* @description The path to the HTML file related to the BrowserWindow
*/
Expand All @@ -101,11 +116,15 @@ export function createElectronRouter<
browserWindow: BrowserWindow
},
>(props: S) {
const devServerUrl = `http://localhost:${props.port ?? port}`
const serverUrl =
props.devServerUrl ||
devServerUrl ||
`http://localhost:${props.port ?? port}`

const windowId = props.id || defaults.windowId

if (isDev()) {
const URLRoute = createURLRoute(devServerUrl, windowId, {
const URLRoute = createURLRoute(serverUrl, windowId, {
query: props.query as Record<string, string>,
})

Expand Down Expand Up @@ -141,6 +160,7 @@ export function createElectronRouter<

const settings = {
port,
devServerUrl,

types: {
strict: types?.strict ?? true,
Expand All @@ -149,6 +169,7 @@ export function createElectronRouter<
},
} as {
port: T['port'] extends number ? T['port'] : typeof defaults.port
devServerUrl: T['devServerUrl']

types: {
strict: Types['strict'] extends boolean ? Types['strict'] : true
Expand Down

0 comments on commit 986f6f8

Please sign in to comment.