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

Cannot read properties of undefined (reading 'use') #131

Closed
markkelsall opened this issue Jan 26, 2023 · 1 comment · Fixed by #132
Closed

Cannot read properties of undefined (reading 'use') #131

markkelsall opened this issue Jan 26, 2023 · 1 comment · Fixed by #132

Comments

@markkelsall
Copy link

Hi,

Thank you for adding in the flexibility to support standard functions as middleware!

However noticed this error when trying to use a function that returns a middleware function e.g.

export const testMiddlewareFunc = (test: string) => {
	return async (req, res, next) => {
		console.log(test);
		next();
	};
};

@Controller("/TestDecorator", [
	async (req: Request, res: Response, next: NextFunction) => {
		console.log("log controller middleware");
		next();
	},
	testMiddlewareFunc("123")
])
export class TestDecoratorController {
	@Get("/:id", [
		async (req: Request, res: Response, next: NextFunction) => {
			console.log("package log route middleware");
			next();
		}
	])

And I get this error
image

Which I think originates from here - https://github.com/serhiisol/node-decorators/blob/master/express/src/middleware.ts#L67

Is it possible to add this flexibility?

Thanks

@serhiisol
Copy link
Owner

Hi @markkelsall. Nice catch, I'll take a look asap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants