-
-
Notifications
You must be signed in to change notification settings - Fork 383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question about blueprints and static routes #585
Comments
Hello. First question - have you tried to run this on |
@mrozigor : I haven't tried master yet. I need to use |
I found it in CMake. Trying to deal with the ASIO dependency. Is that necessary for building crow_all.h? Looks like it's only part of the link libraries. |
You can use script from |
Just did that. Got Cmake working, but Windows doesn't like the wildcard expansion. |
So you generated file properly, but another problem occurred? |
Got I already had to add the 37 boost dependencies as submodules. I can add asio to the list. What version of asio should I reference my submodule to? |
You can use |
Here's the latest setup. I've
I'm still seeing the same behavior as before. The Blueprint is prepending Based on this information, I've tried putting the static files in
They always return 404s. I've once again confirmed that the following code works (with templates and static files in the default directories): #include <crow_all.h>
int main(int argc, char **argv) {
crow::SimpleApp app;
CROW_ROUTE(app, "/")([]() { return "Hello world"; });
CROW_ROUTE(app, "/swagger-ui") ([]() {
auto page = crow::mustache::load("swagger.html");
return page.render();
});
app.port(18080).multithreaded().run();
} |
As I understand correctly HTML loads properly and static files not? Have you tried to change |
I haven't implemented blueprints, so I'd have to check in code. Maybe @The-EDev could help here? |
Great job! I would be great if you prepare PR ;) Thanks. |
Adds static_dir_, templates_dir_, blueprints_, and mw_indices_ to the assignment. This ensures that the Blueprint is assigned all the information.
#585 : Resolves issue with blueprint assignments.
Sorry to hijack this issue but I have a question related to Crow and Swagger: may I ask how did you implement/integrate the OpenAPI spec with Crow? is there some kind of automatic provider or has to be done by hand? If you could post a simple tutorial I'd appreciate. Thank you in advance! |
Hi @xia-stan I know this might be unrelated but I gotta say thank you for this. Your code you shared here contains more info about blueprints than the web docs. I could get up and running easily with it. Again thank you. |
As a note for those who might come later. It's more efficient to create the blueprint in main, and then pass by reference to the generator. This will reduce the number of copies being made. #include <crow_all.h>
void swagger_blueprint(crow::Blueprint& bp) {
CROW_BP_ROUTE(bp, "/")
([]() {
auto page = crow::mustache::load("swagger.html");
return page.render();
});
}
int main(int argc, char** argv) {
crow::SimpleApp app;
CROW_ROUTE(app, "/")([]() { return "Hello world"; });
crow::Blueprint swag_bp("swagger", "swagger/static", "swagger/templates");
swagger_blueprint(swag_bp);
app.register_blueprint(swag_bp);
app.port(18080).multithreaded().run();
} |
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:
all of the static files associated with the blueprint
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
Code
C++ Source
swagger.html
Software / System
The text was updated successfully, but these errors were encountered: