Skip to content

Commit cdb6e5f

Browse files
committed
feat: add localHost option to allow instances to have seperate user hosts from the instance url
1 parent 1eefd8d commit cdb6e5f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+116
-72
lines changed

.config/cypress-devcontainer.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ setupPassword: example_password_please_change_this_or_you_will_get_hacked
2121
# Final accessible URL seen by a user.
2222
url: 'http://misskey.local'
2323

24+
# Use a seperate hostname for federation. All users on this
25+
# instance will appear with this host instead of the one with
26+
# the misskey web url if set.
27+
#localHost: 'misskey.local'
28+
2429
# ONCE YOU HAVE STARTED THE INSTANCE, DO NOT CHANGE THE
2530
# URL SETTINGS AFTER THAT!
2631

.config/docker_example.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
# You can set url from an environment variable instead.
1010
url: https://example.tld/
1111

12+
# Use a seperate hostname for federation. All users on this
13+
# instance will appear with this host instead of the one with
14+
# the misskey web url if set.
15+
#localHost: 'example.tld'
16+
1217
# ONCE YOU HAVE STARTED THE INSTANCE, DO NOT CHANGE THE
1318
# URL SETTINGS AFTER THAT!
1419

.config/example.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@
7979
# Final accessible URL seen by a user.
8080
url: https://example.tld/
8181

82+
# Use a seperate hostname for federation. All users on this
83+
# instance will appear with this host instead of the one with
84+
# the misskey web url if set.
85+
#localHost: 'example.tld'
86+
8287
# ONCE YOU HAVE STARTED THE INSTANCE, DO NOT CHANGE THE
8388
# URL SETTINGS AFTER THAT!
8489

.devcontainer/devcontainer.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
# Final accessible URL seen by a user.
99
url: http://127.0.0.1:3000/
1010

11+
# Use a seperate hostname for federation. All users on this
12+
# instance will appear with this host instead of the one with
13+
# the misskey web url if set.
14+
#localHost: '127.0.0.1:3000'
15+
1116
# ONCE YOU HAVE STARTED THE INSTANCE, DO NOT CHANGE THE
1217
# URL SETTINGS AFTER THAT!
1318

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### General
44
- 依存関係の更新
5+
- Added `localHost` option to allow misskey instances to federate their users on a different host than the one from the accessable web url.
56

67
### Client
78
-

build.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
remote="docker.io"
4+
user="kenshineto"
5+
image="misskey"
6+
tag="latest"
7+
8+
docker buildx build . \
9+
--platform linux/amd64 \
10+
-t "$remote/$user/$image:$tag" \
11+
"$@"

packages/backend/src/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type RedisOptionsSource = Partial<RedisOptions> & {
2626
*/
2727
type Source = {
2828
url?: string;
29+
localHost?: string;
2930
port?: number;
3031
socket?: string;
3132
trustProxy?: FastifyServerOptions['trustProxy'];
@@ -119,6 +120,7 @@ type Source = {
119120

120121
export type Config = {
121122
url: string;
123+
localHost: string;
122124
port: number;
123125
socket: string | undefined;
124126
trustProxy: NonNullable<FastifyServerOptions['trustProxy']>;
@@ -265,6 +267,7 @@ export function loadConfig(): Config {
265267
const hostname = url.hostname;
266268
const scheme = url.protocol.replace(/:$/, '');
267269
const wsScheme = scheme.replace('http', 'ws');
270+
const localHost = config.localHost ?? host;
268271

269272
const dbDb = config.db.db ?? process.env.DATABASE_DB ?? '';
270273
const dbUser = config.db.user ?? process.env.DATABASE_USER ?? '';
@@ -281,6 +284,7 @@ export function loadConfig(): Config {
281284
publishTarballInsteadOfProvideRepositoryUrl: !!config.publishTarballInsteadOfProvideRepositoryUrl,
282285
setupPassword: config.setupPassword,
283286
url: url.origin,
287+
localHost,
284288
port: config.port ?? parseInt(process.env.PORT ?? '', 10),
285289
socket: config.socket,
286290
trustProxy: config.trustProxy ?? [

packages/backend/src/core/MfmService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ export class MfmService {
386386
const remoteUserInfo = mentionedRemoteUsers.find(remoteUser => remoteUser.username.toLowerCase() === username.toLowerCase() && remoteUser.host?.toLowerCase() === host?.toLowerCase());
387387
const href = remoteUserInfo
388388
? (remoteUserInfo.url ? remoteUserInfo.url : remoteUserInfo.uri)
389-
: `${this.config.url}/${acct.endsWith(`@${this.config.url}`) ? acct.substring(0, acct.length - this.config.url.length - 1) : acct}`;
389+
: `${this.config.url}/${acct.endsWith(`@${this.config.localHost}`) ? acct.substring(0, acct.length - this.config.localHost.length - 1) : acct}`;
390390
try {
391391
const url = new URL(href);
392392
return `<a href="${escapeHtml(url.href)}" class="u-url mention">${escapeHtml(acct)}</a>`;

packages/backend/src/core/RemoteUserResolveService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class RemoteUserResolveService {
5656

5757
host = this.utilityService.toPuny(host);
5858

59-
if (host === this.utilityService.toPuny(this.config.host)) {
59+
if ((host === this.utilityService.toPuny(this.config.localHost)) || (host === this.utilityService.toPuny(this.config.host))) {
6060
this.logger.info(`return local user: ${usernameLower}`);
6161
return await this.usersRepository.findOneBy({ usernameLower, host: IsNull() }).then(u => {
6262
if (u == null) {

packages/backend/src/core/UtilityService.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ export class UtilityService {
2626

2727
@bindThis
2828
public getFullApAccount(username: string, host: string | null): string {
29-
return host ? `${username}@${this.toPuny(host)}` : `${username}@${this.toPuny(this.config.host)}`;
29+
return host ? `${username}@${this.toPuny(host)}` : `${username}@${this.toPuny(this.config.localHost)}`;
3030
}
3131

3232
@bindThis
3333
public isSelfHost(host: string | null): boolean {
3434
if (host == null) return true;
35-
return this.toPuny(this.config.host) === this.toPuny(host);
35+
return (this.toPuny(this.config.localHost) === this.toPuny(host)) ||
36+
(this.toPuny(this.config.host) === this.toPuny(host));
3637
}
3738

3839
@bindThis

0 commit comments

Comments
 (0)