do feed
This commit is contained in:
parent
2586dc87c8
commit
e84cf232a5
13 changed files with 605 additions and 139 deletions
28
scripts/get-local-api-url.js
Normal file
28
scripts/get-local-api-url.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
import os from 'node:os'
|
||||
|
||||
/**
|
||||
* Get the private IP addr of the dev machine to use as the API url.
|
||||
* This is preferred to using localhost or 0.0.0.0 because it allows
|
||||
* us to use the dev client from other devices (i.e. phones)
|
||||
* @returns {string}
|
||||
*/
|
||||
export function getLocalApiUrl() {
|
||||
const addresses = Object.values(os.networkInterfaces())
|
||||
.flat()
|
||||
.filter((addr) => !addr.internal)
|
||||
.filter((addr) => addr.family === 'IPv4')
|
||||
.map((addr) => addr.address)
|
||||
|
||||
let address = addresses.find((addr) => addr.startsWith('192.168')) ?? addresses.at(0)
|
||||
|
||||
if (address === undefined) {
|
||||
console.warn("Couldn't identify the local address for the server. falling back to localhost")
|
||||
address = 'localhost'
|
||||
}
|
||||
|
||||
if (addresses.length > 1) {
|
||||
console.warn(`chose API URL ${address} from possible choices: ${addresses.join(', ')}`)
|
||||
}
|
||||
|
||||
return `http://${address}:7295`
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue