@adpt/cloud
Version:
AdaptJS cloud component library
62 lines • 2 kB
JavaScript
;
/*
* Copyright 2019 Unbounded Systems, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@adpt/core");
const url_1 = require("url");
const util_1 = require("util");
/**
* Abstract component for URL routing
* @public
*/
class UrlRouter extends core_1.PrimitiveComponent {
}
UrlRouter.defaultProps = {
port: 80,
};
exports.UrlRouter = UrlRouter;
exports.default = UrlRouter;
/**
* Function to check if the routes prop for {@link http.UrlRouter | UrlRouter} components is valid
* @param routes - routes from {@link http.UrlRouter | UrlRouter} props
*
* @remarks
* Throws and error if the routes are invalid, along with specific error details in the exception
*
* This can be used by concrete implementation of {@link http.UrlRouter | UrlRouter} to check
* their props for validity.
*
* @public
*/
function checkUrlEndpoints(routes) {
const errs = [];
for (const route of routes) {
const ep = route.endpoint;
if (!util_1.isString(ep))
continue;
try {
new url_1.URL(ep);
}
catch (e) {
errs.push(`Invalid endpoint URL for "${route.path}": ${ep} `);
continue;
}
}
if (errs.length !== 0)
throw new Error(`Error in routes for UrlRouter: \n${errs.join("\n")} \n`);
}
exports.checkUrlEndpoints = checkUrlEndpoints;
//# sourceMappingURL=UrlRouter.js.map