diff --git a/src/config.ts b/src/config.ts
index fd208c07..42d6ecb9 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -21,6 +21,17 @@ const Conf = {
get publishRelays() {
return ['wss://relay.mostr.pub'];
},
+ /** Merges the path with the localDomain. */
+ url(path: string): string {
+ if (path.startsWith('/')) {
+ // Path is a path.
+ return new URL(path, Conf.localDomain).toString();
+ } else {
+ // Path is possibly a full URL. Replace the domain.
+ const { pathname } = new URL(path);
+ return new URL(pathname, Conf.localDomain).toString();
+ }
+ },
};
export { Conf };
diff --git a/src/middleware/auth98.ts b/src/middleware/auth98.ts
index 4910b0ed..99865a27 100644
--- a/src/middleware/auth98.ts
+++ b/src/middleware/auth98.ts
@@ -28,7 +28,7 @@ function auth98(opts: Auth98Opts = {}): AppMiddleware {
.refine((event) => {
const url = findTag(event.tags, 'u')?.[1];
try {
- return url === localUrl(c.req.url);
+ return url === Conf.url(c.req.url);
} catch (_e) {
return false;
}
@@ -51,11 +51,6 @@ function auth98(opts: Auth98Opts = {}): AppMiddleware {
};
}
-function localUrl(url: string): string {
- const { pathname } = new URL(url);
- return new URL(pathname, Conf.localDomain).toString();
-}
-
const requireProof: AppMiddleware = async (c, next) => {
const pubkey = c.get('pubkey');
const proof = c.get('proof');
diff --git a/src/note.ts b/src/note.ts
index a4344eae..514044fb 100644
--- a/src/note.ts
+++ b/src/note.ts
@@ -4,13 +4,11 @@ import { linkify, linkifyStr, mime, nip19, nip21 } from '@/deps.ts';
linkify.registerCustomProtocol('nostr', true);
linkify.registerCustomProtocol('wss');
-const url = (path: string) => new URL(path, Conf.localDomain).toString();
-
const linkifyOpts: linkify.Opts = {
render: {
hashtag: ({ content }) => {
const tag = content.replace(/^#/, '');
- const href = url(`/tags/${tag}`);
+ const href = Conf.url(`/tags/${tag}`);
return `#${tag}`;
},
url: ({ content }) => {
@@ -19,7 +17,7 @@ const linkifyOpts: linkify.Opts = {
const pubkey = getDecodedPubkey(decoded);
if (pubkey) {
const name = pubkey.substring(0, 8);
- const href = url(`/users/${pubkey}`);
+ const href = Conf.url(`/users/${pubkey}`);
return `@${name}`;
} else {
return '';