Skip to content

Commit

Permalink
(fix) #310 - router - undefined path should return 404
Browse files Browse the repository at this point in the history
  • Loading branch information
cdimascio committed Jun 13, 2020
1 parent f4c0c2d commit b41cc5c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/middlewares/openapi.metadata.ts
Expand Up @@ -12,7 +12,9 @@ export function applyOpenApiMetadata(
openApiContext: OpenApiContext,
): OpenApiRequestHandler {
return (req: OpenApiRequest, res: Response, next: NextFunction): void => {
if (openApiContext.shouldIgnoreRoute(req.path)) {
// note base path is empty when path is fully qualified i.e. req.path.startsWith('')
const path = req.path.startsWith(req.baseUrl) ? req.path : `${req.baseUrl}/${req.path}`
if (openApiContext.shouldIgnoreRoute(path)) {
return next();
}
const matched = lookupRoute(req);
Expand All @@ -25,7 +27,7 @@ export function applyOpenApiMetadata(
schema: schema,
};
req.params = pathParams;
} else if (openApiContext.isManagedRoute(req.path)) {
} else if (openApiContext.isManagedRoute(path)) {
req.openapi = {};
}
next();
Expand Down

0 comments on commit b41cc5c

Please sign in to comment.