UNPKG

1.78 kBJavaScriptView Raw
1"use strict";
2// Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
3// Node module: @loopback/rest
4// This file is licensed under the MIT License.
5// License text available at https://opensource.org/licenses/MIT
6Object.defineProperty(exports, "__esModule", { value: true });
7exports.RedirectRoute = void 0;
8class RedirectRoute {
9 constructor(sourcePath, targetLocation, statusCode = 303) {
10 this.sourcePath = sourcePath;
11 this.targetLocation = targetLocation;
12 this.statusCode = statusCode;
13 // ResolvedRoute API
14 this.pathParams = [];
15 this.schemas = {};
16 // RouteEntry implementation
17 this.verb = 'get';
18 this.spec = {
19 description: 'LoopBack Redirect route',
20 'x-visibility': 'undocumented',
21 responses: {},
22 };
23 this.path = sourcePath;
24 }
25 async invokeHandler({ response }, args) {
26 response.redirect(this.statusCode, this.targetLocation);
27 }
28 updateBindings(requestContext) {
29 // no-op
30 }
31 describe() {
32 return `Redirect: "${this.sourcePath}" => "${this.targetLocation}"`;
33 }
34 /**
35 * type guard type checker for this class
36 * @param obj
37 */
38 // eslint-disable-next-line @typescript-eslint/no-explicit-any
39 static isRedirectRoute(obj) {
40 var _a;
41 const redirectOptions = obj;
42 if ((redirectOptions === null || redirectOptions === void 0 ? void 0 : redirectOptions.targetLocation) &&
43 ((_a = redirectOptions.spec) === null || _a === void 0 ? void 0 : _a.description) === 'LoopBack Redirect route') {
44 return true;
45 }
46 return false;
47 }
48}
49exports.RedirectRoute = RedirectRoute;
50//# sourceMappingURL=redirect-route.js.map
\No newline at end of file