Comments (18)
That's the default parameter if you want to use decorators.
from node-decorators.
@valentimarco could you show me the error middleware controller and the error you're receiving ?
from node-decorators.
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.
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.
Your controller is missing @Injectable
too. Basically Injectable
marks a controller that it can be injected and can use injection.
from node-decorators.
no they have the decorator
from node-decorators.
https://github.com/serhiisol/decorators-server/blob/master/src/api/auth.ts#L9
from node-decorators.
they have the decorators, i didn't touch the code that i provide
from node-decorators.
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.
I pulled your dist and updated references and it seems to be working.
from node-decorators.
So you suggest to put the initialization of Db connection in a file, and then export it where i need?
from node-decorators.
Yes, in general it would give you better project organization structure.
from node-decorators.
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.
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.
Try this one.
from node-decorators.
ok works. The problem was in the tsconfig.json where was missing the "emitDecoratorMetadata": true
from node-decorators.
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.
That's the default parameter if you want to use decorators.
from node-decorators.
Related Issues (20)
- Feature Request - Plugin Server System HOT 6
- Injection failed for classes with properties in constructor HOT 1
- After Using Next response from other controllers are empty HOT 2
- Cannot read properties of undefined (reading 'use') HOT 1
- Question: example of how to use error middleware? HOT 10
- Feature Request - Dynamic controller (class) instance HOT 9
- Container.get returns a Promise HOT 2
- Feature Request - attach custom decorators HOT 5
- Feature request - Custom http code handling HOT 3
- Typescript v5 injection of type undefined HOT 11
- socket decorator not working HOT 1
- TypeError: Cannot read properties of undefined HOT 4
- Decorators with inheritance HOT 4
- Error while inject property in middelwares HOT 6
- Where is attachMiddleware o how it change? HOT 2
- Where did the flexibility go?! HOT 11
- @Controller & Rest methods no longer work HOT 1
- Can't attach a controller without an error middleware HOT 17
- HttpModule is not exported HOT 21
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-decorators.