Add Matcher to Redirects.
This commit is contained in:
parent
8e96a55661
commit
5888dfdc97
|
@ -2,8 +2,21 @@ import {HostnameParameters} from './hostname.js';
|
||||||
|
|
||||||
export type RedirectParameters = HostnameParameters;
|
export type RedirectParameters = HostnameParameters;
|
||||||
|
|
||||||
|
export type Matcher = {
|
||||||
|
matchType: 'hostname';
|
||||||
|
toMatch: string;
|
||||||
|
};
|
||||||
|
|
||||||
export abstract class Redirect<P extends RedirectParameters> {
|
export abstract class Redirect<P extends RedirectParameters> {
|
||||||
constructor(public parameters: P) {}
|
constructor(public parameters: P & Matcher) {}
|
||||||
|
|
||||||
|
public isMatch(url: URL): boolean {
|
||||||
|
if (this.parameters.matchType === 'hostname') {
|
||||||
|
return url.hostname === this.parameters.toMatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract redirect(url: URL | string): URL;
|
public abstract redirect(url: URL | string): URL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import {RedirectParameters} from './base.js';
|
|
||||||
import {HostnameRedirect} from './hostname.js';
|
import {HostnameRedirect} from './hostname.js';
|
||||||
|
|
||||||
export * from './base.js';
|
export * from './base.js';
|
||||||
|
@ -6,7 +5,7 @@ export * from './hostname.js';
|
||||||
|
|
||||||
export type Redirects = HostnameRedirect;
|
export type Redirects = HostnameRedirect;
|
||||||
|
|
||||||
export function parseRedirect<P extends RedirectParameters>(
|
export function parseRedirect<P extends Redirects['parameters']>(
|
||||||
parameters: P,
|
parameters: P,
|
||||||
): Redirects | undefined {
|
): Redirects | undefined {
|
||||||
if (parameters.type === 'hostname') {
|
if (parameters.type === 'hostname') {
|
||||||
|
|
Loading…
Reference in New Issue