In this project, you'll see the following Midway based practice case (the upper layer uses egg.js) Midway is based on TypeScript development and combines OOP + Class + IoC. midway is similar to nestjs in its design concept
The capabilities supported by Test Service
| ability | Name | progress |
|---|---|---|
| overview | ||
| Controller | ✓ | |
| Services and Refilling | ✓ | |
| Request, response, and application | ✓ | |
| Web middleware | ✓ | |
| start and deploy | ✓ | |
| Basic ability | ||
| Dependency injection | ✓ | |
| Operating environment | ✓ | |
| Multi-environment configuration | ✓ | |
| Parameter checksum conversion | ✓ | |
| Life cycle | ✓ | |
| Component | ✓ | |
| Logger | ✓ | |
| Debug | ✓ | |
| Test | ✓ | |
| enhance | ||
| Cache (Redis) | ✓ | |
| Database(Typegoose) | ✓ | |
| MongoDB | ✓ | |
| Swagger | ✓ | |
| Web | ||
| CORS | ✓ | |
| microservice | ||
| RabbitMQ | ✓ | |
| Common ability | ||
| Token Authentication | ✓ | |
| Authentication middleware | ✓ | |
| Interface response statistics middleware | ✓ | |
| Unified error handling | ✓ | |
| SnowFlake | ✓ | |
| Jaeger | ✓ |
The following environmental support is required to run the project
- Mongo
- Redis
- Jeager
Installation dependency by docker
docker-compose up -d
docker-compose down
Initializing db
docker exec -it mongo mongosh admin
use admin
db.auth('admin','admin')
use test
db.createUser({user:'admin',pwd:'123456',roles:[{role:'readWrite',db:'test'}]})
$ npm i
$ npm run dev
$ open http://localhost:7001/$ npm start
$ npm stop
- Use
npm run lintto check code style. - Use
npm testto run unit test
- Access using Redis as user login credentials
user:accessToken:${id}Cache user Token informationuser:userinfo:${id}Cache user basic information
Jaeger [OpenTracing] (https://opentracing.io/docs/)
This implementation is based on the ctx mechanism and combined with midway's dependency injection to realize non-intrusive spanContext delivery
- Implements interface-level sampling by default
- span can be manually managed if small particle size sampling is required
ctx.tracerManager.startSpan('SpanName1') await doSomethine() ctx.tracerManager.finishSpan()
open http://127.0.0.1:7001/swagger-ui/index.html#/The unit test framework is Mocha.
Support the case for . Skip () . Only () combination of optional * * * * and * * * * to achieve fast,
Suitable for scenarios involving complex, coupled business projects