diff --git a/application.example.yaml b/application.example.yaml
index 13d33a9..bf78495 100644
--- a/application.example.yaml
+++ b/application.example.yaml
@@ -339,3 +339,20 @@ invite.sender.email.email: "matrix-identity@example.org"
# - /var/lib/mxisd/mxisd.db
#
storage.provider.sqlite.database: '/path/to/mxisd.db'
+
+
+######################
+# DNS-related config #
+######################
+# The domain to overwrite
+#
+#dns.overwrite.homeserver.name: 'example.org'
+
+# - 'env' from environment variable specified by value
+# - any other value will use the value as-is as host
+#
+#dns.overwrite.homeserver.type: 'raw'
+
+# The value to use, depending on the type
+#
+#dns.overwrite.homeserver.value: 'localhost:8448'
diff --git a/src/main/groovy/io/kamax/mxisd/config/DnsOverwrite.java b/src/main/groovy/io/kamax/mxisd/config/DnsOverwrite.java
new file mode 100644
index 0000000..fab7cd3
--- /dev/null
+++ b/src/main/groovy/io/kamax/mxisd/config/DnsOverwrite.java
@@ -0,0 +1,52 @@
+/*
+ * mxisd - Matrix Identity Server Daemon
+ * Copyright (C) 2017 Maxime Dor
+ *
+ * https://max.kamax.io/
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package io.kamax.mxisd.config;
+
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.Optional;
+
+@Configuration
+@ConfigurationProperties("dns.overwrite")
+public class DnsOverwrite {
+
+ private Logger log = LoggerFactory.getLogger(DnsOverwrite.class);
+
+ @Autowired
+ private ServerConfig srvCfg;
+
+ @Autowired
+ private DnsOverwriteEntry homeserver;
+
+ public Optional findHost(String lookup) {
+ if (homeserver != null && StringUtils.equalsIgnoreCase(lookup, homeserver.getName())) {
+ return Optional.of(homeserver);
+ }
+
+ return Optional.empty();
+ }
+
+}
diff --git a/src/main/groovy/io/kamax/mxisd/config/DnsOverwriteEntry.java b/src/main/groovy/io/kamax/mxisd/config/DnsOverwriteEntry.java
new file mode 100644
index 0000000..70267c4
--- /dev/null
+++ b/src/main/groovy/io/kamax/mxisd/config/DnsOverwriteEntry.java
@@ -0,0 +1,67 @@
+/*
+ * mxisd - Matrix Identity Server Daemon
+ * Copyright (C) 2017 Maxime Dor
+ *
+ * https://max.kamax.io/
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package io.kamax.mxisd.config;
+
+import org.apache.commons.lang.StringUtils;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@ConfigurationProperties("dns.overwrite.homeserver")
+public class DnsOverwriteEntry {
+
+ private String name;
+ private String type;
+ private String value;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getTarget() {
+ if (StringUtils.equals("env", getType())) {
+ return System.getenv(getValue());
+ } else {
+ return getValue();
+ }
+ }
+
+}
diff --git a/src/main/groovy/io/kamax/mxisd/invitation/InvitationManager.java b/src/main/groovy/io/kamax/mxisd/invitation/InvitationManager.java
index 96a0846..1c60d87 100644
--- a/src/main/groovy/io/kamax/mxisd/invitation/InvitationManager.java
+++ b/src/main/groovy/io/kamax/mxisd/invitation/InvitationManager.java
@@ -22,6 +22,8 @@ package io.kamax.mxisd.invitation;
import com.google.gson.Gson;
import io.kamax.matrix.MatrixID;
+import io.kamax.mxisd.config.DnsOverwrite;
+import io.kamax.mxisd.config.DnsOverwriteEntry;
import io.kamax.mxisd.exception.BadRequestException;
import io.kamax.mxisd.exception.MappingAlreadyExistsException;
import io.kamax.mxisd.invitation.sender.IInviteSender;
@@ -78,6 +80,9 @@ public class InvitationManager {
@Autowired
private SignatureManager signMgr;
+ @Autowired
+ private DnsOverwrite dns;
+
private Map senders;
private CloseableHttpClient client;
@@ -149,6 +154,13 @@ public class InvitationManager {
// TODO use caching mechanism
// TODO export in matrix-java-sdk
String findHomeserverForDomain(String domain) {
+ Optional entryOpt = dns.findHost(domain);
+ if (entryOpt.isPresent()) {
+ DnsOverwriteEntry entry = entryOpt.get();
+ log.info("Found DNS overwrite for {} to {}", entry.getName(), entry.getTarget());
+ return "https://" + entry.getTarget();
+ }
+
log.debug("Performing SRV lookup for {}", domain);
String lookupDns = getSrvRecordName(domain);
log.info("Lookup name: {}", lookupDns);