Skip to content

Commit 66a8a0a

Browse files
core: fix url helper for custom domain (#1162)
Co-authored-by: undefined <i@undefined.moe>
1 parent 879dcff commit 66a8a0a

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

packages/hydrooj/src/service/server.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,14 @@ export async function apply(ctx: Context) {
144144
}
145145
try {
146146
const { anchor } = args;
147-
let withDomainId = args.domainId || false;
148-
const domainId = this.args.domainId;
149-
const host = this.domain?.host;
150-
if (domainId !== 'system' && (
151-
!this.request.host
152-
|| (host instanceof Array
153-
? (!host.includes(this.request.host))
154-
: this.request.host !== host)
155-
)) withDomainId ||= domainId;
147+
const host = this.domain?.host || [];
148+
const target = args.domainId || this.args.domainId;
149+
const rootDomainId = (this.request.host && host?.length && host?.includes(this.request.host))
150+
? this.args.domainId : 'system';
156151
delete args.query;
157152
res = server.router.url(name, args, { query }).toString();
158153
if (anchor) res = `${res}#${anchor}`;
159-
if (withDomainId) res = `/d/${withDomainId}${res}`;
154+
if (target !== rootDomainId) res = `/d/${target}${res}`;
160155
} catch (e) {
161156
logger.warn(e.message);
162157
logger.info('%s %o', name, args);

0 commit comments

Comments
 (0)