Giter Club home page Giter Club logo

Comments (18)

serhiisol avatar serhiisol commented on June 16, 2024 1

That's the default parameter if you want to use decorators.

from node-decorators.

serhiisol avatar serhiisol commented on June 16, 2024

@valentimarco could you show me the error middleware controller and the error you're receiving ?

from node-decorators.

valentimarco avatar valentimarco commented on June 16, 2024
import { ErrorMiddleware, ERROR_MIDDLEWARE } from '@decorators/express';
import {Container, Injectable} from "@decorators/di";
import {NextFunction, Request, Response} from "express";

@Injectable()
export class ServerErrorMiddleware implements ErrorMiddleware {
    public use(error: Error, request: Request, response: Response, next: NextFunction) {
        next();
    }
}

The error i get when trying to call Get endpoint

<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="utf-8">
	<title>Error</title>
</head>

<body>
	<pre>Cannot GET /therapies/7</pre>
</body>

</html>

Only DELETE method works...
No errors in console

from node-decorators.

valentimarco avatar valentimarco commented on June 16, 2024

Update: On the ErrorMiddleware, i inserted a console.log. The error that prints:

TypeError: Cannot read properties of undefined (reading 'getTherapiesbyId')
    at Therapies.getTherapies (/home/marco/WebstormProjects/Microservice/src/Controllers/Therapies.ts:19:45)
    at /home/marco/WebstormProjects/Microservice/node_modules/@decorators/express/src/express.ts:88:43
    at Layer.handle [as handle_request] (/home/marco/WebstormProjects/Microservice/node_modules/express/lib/router/layer.js:95:5)
    at next (/home/marco/WebstormProjects/Microservice/node_modules/express/lib/router/route.js:144:13)
    at Route.dispatch (/home/marco/WebstormProjects/Microservice/node_modules/express/lib/router/route.js:114:3)
    at Layer.handle [as handle_request] (/home/marco/WebstormProjects/Microservice/node_modules/express/lib/router/layer.js:95:5)
    at /home/marco/WebstormProjects/Microservice/node_modules/express/lib/router/index.js:284:15
    at param (/home/marco/WebstormProjects/Microservice/node_modules/express/lib/router/index.js:365:14)
    at param (/home/marco/WebstormProjects/Microservice/node_modules/express/lib/router/index.js:376:14)
    at Function.process_params (/home/marco/WebstormProjects/Microservice/node_modules/express/lib/router/index.js:421:3)

This is normal, because the service is undefined and this proves that DI don't work

from node-decorators.

serhiisol avatar serhiisol commented on June 16, 2024

Your controller is missing @Injectable too. Basically Injectable marks a controller that it can be injected and can use injection.

from node-decorators.

valentimarco avatar valentimarco commented on June 16, 2024

no they have the decorator

from node-decorators.

serhiisol avatar serhiisol commented on June 16, 2024

https://github.com/serhiisol/decorators-server/blob/master/src/api/auth.ts#L9

from node-decorators.

valentimarco avatar valentimarco commented on June 16, 2024

they have the decorators, i didn't touch the code that i provide

from node-decorators.

serhiisol avatar serhiisol commented on June 16, 2024

I believe that the problem is related to circular dependency issue there. Basically you need to extract DB connection initialization into additional file and import it instead of index.ts in the [TherapiesService.ts](https://gist.github.com/valentimarco/2638b81d79fff32a3b4cfa28d2bfb2c5#file-therapiesservice-ts)

from node-decorators.

serhiisol avatar serhiisol commented on June 16, 2024

I pulled your dist and updated references and it seems to be working.

from node-decorators.

valentimarco avatar valentimarco commented on June 16, 2024

So you suggest to put the initialization of Db connection in a file, and then export it where i need?

from node-decorators.

serhiisol avatar serhiisol commented on June 16, 2024

Yes, in general it would give you better project organization structure.

from node-decorators.

serhiisol avatar serhiisol commented on June 16, 2024

In index.ts file you would just need to use start connection method or something, but in the services you would need to use connection object only. Also you can use Container to provide connection there and in the services you would need to use injection token instead to inject connection object.

from node-decorators.

valentimarco avatar valentimarco commented on June 16, 2024

i have updated the gist. The problem persist even if i create a new file with only the CoreDb instance and a method startconnection in the index.ts

from node-decorators.

serhiisol avatar serhiisol commented on June 16, 2024

node_modules.zip

Try this one.

from node-decorators.

valentimarco avatar valentimarco commented on June 16, 2024

ok works. The problem was in the tsconfig.json where was missing the "emitDecoratorMetadata": true

from node-decorators.

valentimarco avatar valentimarco commented on June 16, 2024

Suggestion: Can you write it in docs that needs this param in the tsconfig? I see now that you added a tsconfig.example.json but this isn't enough.

from node-decorators.

valentimarco avatar valentimarco commented on June 16, 2024

That's the default parameter if you want to use decorators.

🤣 My bad

from node-decorators.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.