2022-10-20 14:22:57 +00:00
|
|
|
import {RedirectParameters} from './base.js';
|
2022-10-05 17:08:17 +00:00
|
|
|
import {HostnameRedirect} from './hostname.js';
|
2022-11-02 10:10:29 +00:00
|
|
|
import {RegexRedirect} from './regex.js';
|
2022-10-18 16:29:01 +00:00
|
|
|
import {SimpleRedirect} from './simple.js';
|
2022-10-05 17:08:17 +00:00
|
|
|
|
|
|
|
export * from './base.js';
|
|
|
|
export * from './hostname.js';
|
2022-11-02 10:10:29 +00:00
|
|
|
export * from './regex.js';
|
2022-10-18 16:29:01 +00:00
|
|
|
export * from './simple.js';
|
2022-10-05 17:08:17 +00:00
|
|
|
|
2022-10-18 16:29:01 +00:00
|
|
|
export type Redirects = HostnameRedirect | SimpleRedirect;
|
2022-10-05 17:08:17 +00:00
|
|
|
|
2022-10-20 14:22:57 +00:00
|
|
|
export function parseRedirect(
|
|
|
|
parameters: RedirectParameters,
|
2022-10-05 17:08:17 +00:00
|
|
|
): Redirects | undefined {
|
2022-11-02 10:10:29 +00:00
|
|
|
const matcherType = parameters?.matcherType;
|
2022-10-18 20:21:55 +00:00
|
|
|
const redirectType = parameters?.redirectType;
|
2022-10-18 16:59:05 +00:00
|
|
|
|
2022-10-18 20:21:55 +00:00
|
|
|
if (redirectType === 'hostname') {
|
2022-10-27 19:13:02 +00:00
|
|
|
return new HostnameRedirect(parameters);
|
2022-10-05 17:08:17 +00:00
|
|
|
}
|
2022-10-18 16:59:05 +00:00
|
|
|
|
2022-10-18 20:21:55 +00:00
|
|
|
if (redirectType === 'simple') {
|
2022-10-27 19:13:02 +00:00
|
|
|
return new SimpleRedirect(parameters);
|
2022-10-18 16:59:05 +00:00
|
|
|
}
|
2022-11-02 10:10:29 +00:00
|
|
|
|
|
|
|
if (matcherType === 'regex' && redirectType === 'regex') {
|
|
|
|
return new RegexRedirect(parameters);
|
|
|
|
}
|
2022-10-05 17:08:17 +00:00
|
|
|
}
|