mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-04 00:28:33 +00:00
feat(server): add LISTEN_ADDR env var for allowing server to listen on ipv6 (#14211)
The old code hardcoded 0.0.0.0 which means the server only listened for
ipv4 connections, making it not work on ipv6-only networks.
This change adds a LISTEN_ADDR env var which allows the server to bind
to ipv6 as well.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Server listen address is now configurable via the LISTEN_ADDR
environment variable (default: 0.0.0.0), enabling IPv4/IPv6 or
interface-specific binding.
* Configuration schemas and admin UI now expose the listen address
option so deployments can view and override it.
<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -13,6 +13,7 @@ declare global {
|
||||
https: boolean;
|
||||
host: string;
|
||||
hosts: ConfigItem<string[]>;
|
||||
listenAddr: string;
|
||||
port: number;
|
||||
path: string;
|
||||
name?: string;
|
||||
@@ -58,6 +59,11 @@ Default to be \`[server.protocol]://[server.host][:server.port]\` if not specifi
|
||||
default: [],
|
||||
shape: z.array(z.string()),
|
||||
},
|
||||
listenAddr: {
|
||||
desc: 'The address to listen on (e.g., 0.0.0.0 for IPv4, :: for IPv6).',
|
||||
default: '0.0.0.0',
|
||||
env: 'LISTEN_ADDR',
|
||||
},
|
||||
port: {
|
||||
desc: 'Which port the server will listen on.',
|
||||
default: 3010,
|
||||
|
||||
@@ -75,11 +75,14 @@ export async function run() {
|
||||
}
|
||||
|
||||
const url = app.get(URLHelper);
|
||||
const listeningHost = '0.0.0.0';
|
||||
|
||||
await app.listen(config.server.port, listeningHost);
|
||||
await app.listen(config.server.port, config.server.listenAddr);
|
||||
|
||||
const formattedAddr = config.server.listenAddr.includes(':')
|
||||
? `[${config.server.listenAddr}]`
|
||||
: config.server.listenAddr;
|
||||
|
||||
logger.log(`AFFiNE Server is running in [${env.DEPLOYMENT_TYPE}] mode`);
|
||||
logger.log(`Listening on http://${listeningHost}:${config.server.port}`);
|
||||
logger.log(`Listening on http://${formattedAddr}:${config.server.port}`);
|
||||
logger.log(`And the public server should be recognized as ${url.baseUrl}`);
|
||||
}
|
||||
|
||||
@@ -216,6 +216,11 @@
|
||||
"type": "Array",
|
||||
"desc": "Multiple hosts the server will accept requests from."
|
||||
},
|
||||
"listenAddr": {
|
||||
"type": "String",
|
||||
"desc": "The address to listen on (e.g., 0.0.0.0 for IPv4, :: for IPv6).",
|
||||
"env": "LISTEN_ADDR"
|
||||
},
|
||||
"port": {
|
||||
"type": "Number",
|
||||
"desc": "Which port the server will listen on.",
|
||||
|
||||
Reference in New Issue
Block a user