From 75a9799e9633c4c833c29874ad7ca45fa32e3a81 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Wed, 10 Aug 2022 14:05:16 +0200 Subject: [PATCH] feat(xo-server): make http.listen config an object It remains compatible with previous configurations. It now aligns with xo-proxy's config and is easier to overload with other config files. --- CHANGELOG.unreleased.md | 1 + packages/xo-server/config.toml | 10 +++++++++- packages/xo-server/src/index.mjs | 5 ++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index ebe2cc1bd..7965fbd26 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -29,5 +29,6 @@ - @xen-orchestra/fs minor - vhd-lib major +- xo-server minor diff --git a/packages/xo-server/config.toml b/packages/xo-server/config.toml index 1dd098f46..307b33ff3 100644 --- a/packages/xo-server/config.toml +++ b/packages/xo-server/config.toml @@ -105,7 +105,15 @@ threshold = 1000 #[http.helmet.hsts] #includeSubDomains = false -[[http.listen]] +# Each `http.listen.` entry defines a specific listening configuration for +# the HTTP server. +# +# `` can be freely choosen. +# +# Historically, `http.listen` was an array with the first config for HTTP and +# the second for HTTPS. To avoid breaking existing user configs, this convention +# is kept. +[http.listen.0] port = 80 # These options are applied to all listen entries. diff --git a/packages/xo-server/src/index.mjs b/packages/xo-server/src/index.mjs index 116b708e3..bf57cf91f 100644 --- a/packages/xo-server/src/index.mjs +++ b/packages/xo-server/src/index.mjs @@ -11,7 +11,6 @@ import has from 'lodash/has.js' import helmet from 'helmet' import httpProxy from 'http-proxy' import includes from 'lodash/includes.js' -import map from 'lodash/map.js' import memoryStoreFactory from 'memorystore' import merge from 'lodash/merge.js' import ms from 'ms' @@ -474,8 +473,8 @@ async function makeWebServerListen( async function createWebServer({ listen, listenOptions }) { const webServer = stoppable(new WebServer()) - await Promise.all( - map(listen, (opts, configKey) => makeWebServerListen(webServer, { ...listenOptions, ...opts, configKey })) + await asyncMap(Object.entries(listen), ([configKey, opts]) => + makeWebServerListen(webServer, { ...listenOptions, ...opts, configKey }) ) return webServer