2022-10-05 17:08:17 +00:00
|
|
|
import {HostnameParameters} from './hostname.js';
|
2022-10-18 16:29:01 +00:00
|
|
|
import {SimpleParameters} from './simple.js';
|
2022-10-05 17:08:17 +00:00
|
|
|
|
2022-10-18 16:29:01 +00:00
|
|
|
export type RedirectParameters = HostnameParameters | SimpleParameters;
|
2022-10-05 17:08:17 +00:00
|
|
|
|
2022-10-12 22:04:51 +00:00
|
|
|
export type Matcher = {
|
|
|
|
matchType: 'hostname';
|
|
|
|
toMatch: string;
|
|
|
|
};
|
|
|
|
|
2022-10-05 17:08:17 +00:00
|
|
|
export abstract class Redirect<P extends RedirectParameters> {
|
2022-10-12 22:04:51 +00:00
|
|
|
constructor(public parameters: P & Matcher) {}
|
|
|
|
|
|
|
|
public isMatch(url: URL): boolean {
|
|
|
|
if (this.parameters.matchType === 'hostname') {
|
|
|
|
return url.hostname === this.parameters.toMatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2022-10-05 17:08:17 +00:00
|
|
|
|
|
|
|
public abstract redirect(url: URL | string): URL;
|
|
|
|
}
|