- Support typeorm, the best typescript ORM framework, and easily write all kinds of logic of Dao layer
- Allow static type modification and type inference to support back-end development and maintenance
- Modular development makes the application easier to layer and provides an easy-to-use modular management mechanism
- AOP code is written in a low-key way, but it is easy to realize log, interceptor, filter and other functions
- MVC, API, websocket, microservice and other systems are constructed fastest, good and most fiercely
- The configuration is greater than the code, and priority is given to automatically implement five methods, such as adding, deleting, modifying and querying, and pagination, to facilitate the establishment of authority background system
- With the field level RBAC and pluggable middleware decorator, the assembly function has unlimited possibilities
- Support for serverless, the introduction of router in the controller method, you can easily change the background page, or even write to a file
- Multiple databases are allowed, as long as it is a relational database allowed by typeorm. Currently, MySQL and Postgres have been provided
- Add the example directory of socketio demo[the default is management Version (the default password of Redis is 6543210)]
- Method override can be used to replace the curdp method generated automatically, so that there is no need to worry about whether there is redundancy in the routing
- From the ES6 magic function generator generator, plus the whole asynchronous to further improve efficiency, so stable, extremely fast
Thinkts refers to the implementation of [ThinkPHP + Nestjs + FastAPI]. Of course, the purpose is also for product managers. The idea is that it is possible to achieve a small goal (project) every day…
@Class(["add","del","fix","info","page"])//or @Class("/admin",……)or @Class("admin",……)
class Admin extends Controller{
@Inject(Admin$) readonly a_:Admin$
@Inject(User$) readonly u_:User$
@Middle(W.Log,W.V_B("account|1#3~10","pwd#6~23|1"))
@app.post("register")
add(@B b,@R r:Response) {
r.status=202;//Set status code
return this.u_.register(b.account,b.pwd)
}
}
/** Here's how to show EJS template rendering */
class View{
@Get() @Get("index.html")
index(ctx:Context){
html(ctx,{test:"test",author:"asciphx"}).next().value
}
@Get("login.html")
login(ctx:Context){
html(ctx,{test:"test",author:"Login"}).next().value
}
}
export default class User$ extends $ implements F{
constructor(
private u=Inject(User),private r=Inject(Role)
) {
super({
leftJoin:{e:"u.roles",a:'role'},
addSelect:['role.id','role.name'],
where: query => new Brackets(qb => {
if (query.account) qb.where('account like :v', { v: `%${query.account}%` })
if (query.id) qb.andWhere('u.id >:i', { i: query.id })
}),
orderBy: { "u.id": "desc" }
},"u")
}
}
export default interface UserFace{
/** register one*/register(entity)
/** login one*/login(entity)
}
Finally, please refer to the entity class writing method of TypeORM
- The default value of class class decorator is
/
+ entity class name, which can also be customized - Automatically scan controller directory and configure routes route
- Automatically scan the entity directory and load it into Cache, which is equivalent to a container, which can avoid multiple instances of entity
- Automatically generate the configuration route file for reference, which is under the routes directory
- Automatic implementation of addition, deletion, modification and query
- Now add the basic controller and service layer. The controller decorator can be customized to automatically add, delete, modify, query and pagination.
- The controller can now customize the name of the service class variable to be called.
- In order to reduce memory overhead and instance calls, we have implemented the containerization of entity classes.
- Add parameter decorator, more convenient and beautiful, and will not affect the running speed
- decorators can be placed horizontally, and can be stacked, and the order is from right to left
The header request header now has two parameters, and the original JWT does not change. Now add a secret. Secret is now provided by the back end. The algorithm is in the cryptoUtil.ts in
t:`${token}` s:`${secret}`In particular, localhost:8080/index.html It is the postman interface. Remember to record token and sercet after login and use it as above. The front-end is still in implementation. Let's use postman for a while. For instructions started in a formal environment, windows uses NPM run pro, while MAC or Linux uses NPM run prod
- Run
npm i
command - Setup database settings inside
ormconfig.json
file - Run
npm start
command
Please refer to nestjs's microservice pattern document, which can be basically implemented
menu path,automatically generated(Matching rule)
Add:POST/admin
Delete:DELETE/admin/
Modification:PUT/admin/
Query:GET/admin/
Pagination:GET/admin
The return value in restful specification actually costs too much bandwidth. However, I think the front end only needs to judge whether the return is a string or an object. For example, the string is displayed directly (the front-end pop-up window is OK), If an object is returned, the request status code must be 200, so only the important data is taken without the code status code and mass message to indicate success (those two things are totally a waste of traffic).
- app:
back end file entry
- app/controller:
control layer
-> /^[A-Z_]\w*/ - app/entity:
entity layer
- app/interface:
interface layer
- app/service:
service layer
- app/think:
base layer
- app/utils:
tool layer
- dist:
background EJS template rendering folder/front end packaging folder
- lib:
Windows uses the RM and CP instructions of Linux, and needs to put the environment variable directory
- routes:
Provide front-end routing file. Each controller will create one
- upload:
the storage directory of the uploaded file
- build:
package back end to formal environment directory
- log:
PM2 output log directory
- Example:
save the template of permission management, as well as the common template
Built by the world's No.1 man, Asciphx
Please wait this project will generate a blog project