| 9 | import {OperationArgs, OperationRetval, PathParameterValues} from '../types'; |
| 10 | |
| 11 | export class RedirectRoute implements RouteEntry, ResolvedRoute { |
| 12 | // ResolvedRoute API |
| 13 | readonly pathParams: PathParameterValues = []; |
| 14 | readonly schemas: SchemasObject = {}; |
| 15 | |
| 16 | // RouteEntry implementation |
| 17 | readonly verb: string = 'get'; |
| 18 | readonly path: string; |
| 19 | readonly spec: OperationObject = { |
| 20 | description: 'LoopBack Redirect route', |
| 21 | 'x-visibility': 'undocumented', |
| 22 | responses: {}, |
| 23 | }; |
| 24 | |
| 25 | constructor( |
| 26 | public readonly sourcePath: string, |
| 27 | public readonly targetLocation: string, |
| 28 | public readonly statusCode: number = 303, |
| 29 | ) { |
| 30 | this.path = sourcePath; |
| 31 | } |
| 32 | |
| 33 | async invokeHandler( |
| 34 | {response}: RequestContext, |
| 35 | args: OperationArgs, |
| 36 | ): Promise<OperationRetval> { |
| 37 | response.redirect(this.statusCode, this.targetLocation); |
| 38 | } |
| 39 | |
| 40 | updateBindings(requestContext: RequestContext) { |
| 41 | // no-op |
| 42 | } |
| 43 | |
| 44 | describe(): string { |
| 45 | return `Redirect: "${this.sourcePath}" => "${this.targetLocation}"`; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * type guard type checker for this class |
| 50 | * @param obj |
| 51 | */ |
| 52 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 53 | static isRedirectRoute(obj: any): obj is RedirectRoute { |
| 54 | const redirectOptions = obj as RedirectRoute; |
| 55 | if ( |
| 56 | redirectOptions?.targetLocation && |
| 57 | redirectOptions.spec?.description === 'LoopBack Redirect route' |
| 58 | ) { |
| 59 | return true; |
| 60 | } |
| 61 | return false; |
| 62 | } |
| 63 | } |
nothing calls this directly
no outgoing calls
no test coverage detected