UNPKG

@5minds/processcube_engine

Version:

The ProcessCube Engine. Stores and executes BPMNs.

64 lines 2.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createIsPublicRouteMiddleware = createIsPublicRouteMiddleware; const matchesParametrizedRoute = (route, url) => { if (route === url) { return true; } const routeSegments = route.split('/'); const urlSegments = url.split('/'); if (routeSegments.length !== urlSegments.length) { return false; } for (let i = 0; i < routeSegments.length; i++) { const isParametrizedSegment = routeSegments[i].startsWith(':'); if (!isParametrizedSegment && routeSegments[i] !== urlSegments[i]) { return false; } } return true; }; // The routes listed here require no identity. const publicRoutes = { get: [ '/', '/v1/info', '/v1/authority', '/swagger', '/v1/swagger', '/atlas_engine', '/security/authority', '/atlas_engine/security/authority', '/favicon-32x32.png', '/favicon-16x16.png', ], post: [], put: [], delete: [], }; function createIsPublicRouteMiddleware(extensionRoutes) { for (const extensionRoute of extensionRoutes) { if (extensionRoute.options?.protected === false) { publicRoutes[extensionRoute.method].push(extensionRoute.route); } } return async (request, response, next) => { const urlWithoutParams = request.url.split('?')[0]; const method = request.method.toLowerCase(); const isSwaggerUiRoute = /^\/swagger-ui*/i.test(urlWithoutParams); if (isSwaggerUiRoute) { response.locals.isPublicRoute = true; next(); return; } for (const route of publicRoutes[method]) { if (matchesParametrizedRoute(route, urlWithoutParams)) { response.locals.isPublicRoute = true; next(); return; } } next(); }; } //# sourceMappingURL=IsPublicRouteMiddleware.js.map