Skip to content
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

Using local middleware in a blueprint #391

Closed
SSIvanov19 opened this issue Apr 7, 2022 · 2 comments · Fixed by #396
Closed

Using local middleware in a blueprint #391

SSIvanov19 opened this issue Apr 7, 2022 · 2 comments · Fixed by #396
Labels
bug Something isn't working
Milestone

Comments

@SSIvanov19
Copy link

SSIvanov19 commented Apr 7, 2022

Hello,
I am trying to use local middleware in a blueprint.

I defined my application as follows:

crow::App<crow::CORSHandler, AuthorisationMiddleware> app;

Then I define my blueprint

crow::Blueprint api = initApi(app);
app.register_blueprint(api);

initApi() function contains:

crow::Blueprint initApi(crow::App<crow::CORSHandler, AuthorisationMiddleware> &app)
{
	crow::Blueprint api("api");
	CROW_BP_ROUTE(api, "/users/<string>")
		.methods(crow::HTTPMethod::Delete)
		.CROW_MIDDLEWARES(app, AuthorisationMiddleware)
		([&](const crow::request& req, crow::response& res, std::string username)
			{
				// Handler continues here
				res.end();
				return;
			});

	return api;
}

But when I try to compile, I am getting the following errors:

error C2672: 'operator __surrogate_func': no matching overloaded function found
error C2783: 'void crow::detail::handler_call_bridge<crow::TaggedRule<crow::black_magic::single_tag_to_type<4>::type>,crow::Crow<crow::CORSHandler,AuthorisationMiddleware> &,AuthorisationMiddleware>::operator ()(F &&)': could not deduce template argument for 'F'
@The-EDev The-EDev added the bug Something isn't working label Apr 7, 2022
@The-EDev
Copy link
Member

The-EDev commented Apr 7, 2022

I tried to recreate this but got a different error:

error: ‘crow::Crow<AuthorisationMiddleware>&’ is not a class, struct, or union type

I fixed that by using the middlewares() method directly instead of CROW_MIDDLEWARES (the line was .middlewares<crow::App<AuthorisationMiddleware>, AuthorisationMiddleware>())

@SSIvanov19
Copy link
Author

Thanks for the reply!
When I use the method instead of the macro, it works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants