Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

ports.js

26 lines620 Bytes

1const DEFAULT_DEMO_PORT = 4183
2const DEFAULT_API_PORT = 4184
3​
4function readPortFromEnv(name, fallback) {
5 const rawValue = process.env[name]
6 if (!rawValue) {
7 return fallback
8 }
9​
10 const parsed = Number.parseInt(rawValue, 10)
11 const valid = Number.isInteger(parsed) && parsed >= 1 && parsed <= 65535
12​
13 if (!valid) {
14 throw new Error(
15 `Invalid ${name}="${rawValue}". Expected integer in [1, 65535].`,
16 )
17 }
18​
19 return parsed
21​
22export const DEMO_PORT = readPortFromEnv(
23 'PAGINATION_DEMO_PORT',
24 DEFAULT_DEMO_PORT,
26export const API_PORT = readPortFromEnv('PAGINATION_API_PORT', DEFAULT_API_PORT)