-
-
Notifications
You must be signed in to change notification settings - Fork 469
Description
I'm serving my OpenAPI specification using the Swagger UI framework. I've got everything working using the SimpleApp object. I'm reworking the code to use blueprints. I am having trouble with the server not finding files in the expected paths. When using a blueprint with no overrides, I expect to need the following directory structure:
- server.exe
- swagger/
- static/
all of the static files associated with the blueprint
- static/
- templates/
- swagger.html
The endpoint should be http://localhost:18080/swagger/
. Logging (see below) shows that we find the template in the right spot (templates/
) but it's looking for the static files with the /swagger/
prefix. The documentation notes that the final routes should be <bp prefix>/static/<filename>
, which doesn't seem to be working as expected.
I've also reviewed #497. In my case, I just want the default behavior.
Logs
(2023-01-17 20:41:53) [INFO ] Crow/1.0 server is running at http://0.0.0.0:18080 using 16 threads
(2023-01-17 20:41:53) [INFO ] Callapp.loglevel(crow::LogLevel::Warning)
to hide Info level logs.
(2023-01-17 20:42:09) [INFO ] Request: 127.0.0.1:59614 000001492F43A430 HTTP/1.1 GET /swagger/
(2023-01-17 20:42:09) [INFO ] Response: 000001492F43A430 /swagger/ 200 0
(2023-01-17 20:42:09) [INFO ] Request: 127.0.0.1:59614 000001492F43A430 HTTP/1.1 GET /swagger/swagger-ui.css
(2023-01-17 20:42:09) [INFO ] Response: 000001492F43A430 /swagger/swagger-ui.css 404 0
(2023-01-17 20:42:09) [INFO ] Request: 127.0.0.1:59614 000001492F43A430 HTTP/1.1 GET /swagger/static/swagger.css
(2023-01-17 20:42:09) [INFO ] Response: 000001492F43A430 /swagger/static/swagger.css 404 0
Code
C++ Source
#include <crow_all.h>
int main(int argc, char **argv) {
crow::SimpleApp app;
crow::Blueprint bp("swagger");
app.register_blueprint(bp);
CROW_BP_ROUTE(bp, "/")
([]() {
auto page = crow::mustache::load("swagger.html");
return page.render();
});
app.port(18080).multithreaded().run();
}
swagger.html
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="static/swagger-ui.css" />
<link rel="stylesheet" type="text/css" href="static/swagger.css" />
<link rel="icon" type="image/png" href="static/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="static/favicon-16x16.png" sizes="16x16" />
</head>
<body>
<div id="swagger-ui"></div>
<script src="static/swagger-ui-bundle.js" charset="UTF-8"> </script>
<script src="static/swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
<script src="static/swagger-initializer.js" charset="UTF-8"> </script>
</body>
</html>
Software / System
- Windows 11 Pro 22H2
- Crow v1.0+5 Security Patch (crow_all.h)
- MSVC 19.29.30146.0