Listen on IPv6 as well as IPv4 by default #75

Merged
jcoffey-dev merged 1 commits from fix/ipv6-listen into main 2026-10-26 13:23:53 +00:00
4 changed files with 23 additions and 5 deletions

No files matched your search

+2 -2
View File
@@ -8,8 +8,8 @@ MAIL_SERVER_URL=https://mail.example.com
# Generate with: openssl rand -base64 48
APP_SECRET=change-me
# Listen address
HOST=0.0.0.0
# Listen address. :: answers on IPv6 and IPv4 alike; 0.0.0.0 is IPv4 only.
HOST=::
PORT=8080
# Serve the app from a subpath instead of the domain root, for a reverse proxy
+1 -1
View File
@@ -33,7 +33,7 @@ FROM mirror.gcr.io/library/node:26-alpine AS runtime
ARG IHASMAIL_VERSION=""
ARG BASE_PATH=""
ENV NODE_ENV=production \
HOST=0.0.0.0 \
HOST=:: \
PORT=8080 \
STATIC_DIR=/app/web/dist \
SESSION_FILE=/data/sessions.json \
+6 -1
View File
@@ -302,7 +302,12 @@ export const config = {
* container's hostname. See nodes.ts.
*/
nodeName: env("NODE_NAME", ""),
host: env("HOST", "0.0.0.0"),
/**
* The address to listen on. `::` takes IPv6 and IPv4 on one socket; a
* kernel without IPv6 at all refuses it, and index.ts then falls back to
* `0.0.0.0` rather than failing to start.
*/
host: env("HOST", "::"),
port: int("PORT", 8080),
/**
* The subpath this instance answers on: `/mail` for a proxy that maps
+14 -1
View File
@@ -6,10 +6,23 @@ async function main() {
await sessions.init();
const app = createApp();
const server = serve({ fetch: app.fetch, hostname: config.host, port: config.port }, (info) => {
console.log(`[ihasmail] ${config.appName} listening on http://${info.address}:${info.port}`);
const address = info.address.includes(":") ? `[${info.address}]` : info.address;
console.log(`[ihasmail] ${config.appName} listening on http://${address}:${info.port}`);
console.log(`[ihasmail] mail server: ${config.stalwartUrl}`);
console.log(`[ihasmail] static dir: ${config.staticDir}`);
});
// `::` is the default, and a kernel booted without IPv6 cannot open it at
// all. Listening on IPv4 alone is still a working server; refusing to start
// over an address family nobody asked for is not.
server.once("error", (err: NodeJS.ErrnoException) => {
if (config.host === "::" && err.code === "EAFNOSUPPORT") {
console.log("[ihasmail] no IPv6 on this host, listening on IPv4 only");
server.listen(config.port, "0.0.0.0");
return;
}
console.error("[ihasmail] fatal:", err);
process.exit(1);
});
const shutdown = async (signal: string) => {
console.log(`[ihasmail] ${signal} received, shutting down`);