Add SimpleRedirect.

This commit is contained in:
Bauke 2022-10-18 18:29:01 +02:00
parent 263c0497f3
commit 1c7d4ca34b
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
3 changed files with 17 additions and 2 deletions

View File

@ -1,6 +1,7 @@
import {HostnameParameters} from './hostname.js'; import {HostnameParameters} from './hostname.js';
import {SimpleParameters} from './simple.js';
export type RedirectParameters = HostnameParameters; export type RedirectParameters = HostnameParameters | SimpleParameters;
export type Matcher = { export type Matcher = {
matchType: 'hostname'; matchType: 'hostname';

View File

@ -1,9 +1,11 @@
import {HostnameRedirect} from './hostname.js'; import {HostnameRedirect} from './hostname.js';
import {SimpleRedirect} from './simple.js';
export * from './base.js'; export * from './base.js';
export * from './hostname.js'; export * from './hostname.js';
export * from './simple.js';
export type Redirects = HostnameRedirect; export type Redirects = HostnameRedirect | SimpleRedirect;
export function parseRedirect<P extends Redirects['parameters']>( export function parseRedirect<P extends Redirects['parameters']>(
parameters: P, parameters: P,

12
source/redirect/simple.ts Normal file
View File

@ -0,0 +1,12 @@
import {Redirect} from './base.js';
export type SimpleParameters = {
target: string;
type: 'simple';
};
export class SimpleRedirect extends Redirect<SimpleParameters> {
public redirect(): URL {
return new URL(this.parameters.target);
}
}