Daze. Js is a Node.js server-side Web development framework. The bottom layer is implemented based on IOC container pattern, using decorator for dependency injection, combined with AOP pattern programming
The Babel ecology is dependent on the use of decorators for dependency injection
features
-
Based on IOC container pattern design, module depth decoupling
-
Support for AOP programming to isolate parts of business logic
-
Routes are decentralized. Routes are defined through injection to improve reading quality
-
Multiple component types are built in for complex scenarios
-
Support for custom providers with high scalability
-
Automatic loading components automatic classification registration, excellent automatic experience
-
More…
The target
Make the best development experience possible
Example
const { Controller, Route, Http } = require('@dazejs/framework')
@Route('/superman')
class Superman extends Controller {
@Http.Get('/create')
create() {
return this.response().Created()
}
}Copy the code
The example above is code for a Controller that uses the @Route decorator to indicate that it is a routing Controller with a Route prefix of /superman. The Controller inherits the base Controller, Controller, to indicate that it is a Controller module. Use the http. Get decorator to open up the /superman/create access path. We can use Get/Superman /create to access the resource. Create a response with status code 201 Created using this.response().created ()
The directory structure
. ├ ─ ─ dist/pack/target directory ├ ─ ─ logs / / log directory ├ ─ ─ package. The json ├ ─ ─ public / / static resource directory ├ ─ ─ SRC / / source directory │ ├ ─ ─ app / / application directory │ │ ├ ─ ─ Controller / / controller directory (recommended) │ │ ├ ─ ─ middleware / / middleware (recommended) │ │ ├ ─ ─ service / / service directory (recommended) │ │ ├ ─ ─ the resource / / API (recommended) │ resource directory │ ├ ─ ─ component / / common component (recommended) │ │ ├ ─ ─ the validator / / validator (recommended) │ ├ ─ ─ the config / / application configuration directory │ └ ─ ─ index. The js / / application entry documents └ ─ ─ views // View file directoryCopy the code
The directory structure under SRC /app can be customized
The controller
Routing parameters
The routing parameter framework has been automatically injected through the controller method and can be obtained by defining the order of routing parameters
const { Controller, Route, Http } = require('@dazejs/framework')
@Route('/superman')
class Superman extends Controller {
@Http.Get('/create/:name/:driver')
create(name, driver) {
return { name, driver }
}
}Copy the code
When we visit/seen superman/create/xiaoming/lily, we can directly obtained through the parameter name and driver
request
In controllers, request instances can be obtained directly from controller instances
const { Controller, Route, Http } = require('@dazejs/framework')
@Route('/superman')
class Superman extends Controller {
@Http.Get('/create')
create() {
const name = this.request.getParam('name')
return name
}
}Copy the code
In the above example, if we visit /superman/create? GetParam (‘name’) {this.request.getParam(‘name’);
The response
Most of the time we just need to return data directly from the controller to return results. The framework also supports returning resource instances, view instances, response instances, etc
Response (data, code, headers) :
const { Controller, Route, Http } = require('@dazejs/framework')
@Route('/superman')
class Superman extends Controller {
@Http.Get('/create')
create() {
return this.response('data', 200, {
'conetent-type': 'application/json'}}})Copy the code
The response instance also provides more useful methods, which can be found in the official documentation (available at the end of this article)
More functions
Daze. Js has just released version 1.0, and it already has more features than one article can cover, so you can look forward to future articles or follow the project to learn more, as well as more feature iteration plans
There will be more in-depth articles on usage and principles to follow
This is just the first step to open source
Function plan
-
websocket
-
granphQL
-
Dubbo
-
DB
-
ORM
-
More…
You can issue more ideas: github.com/dazejs/daze…
Portal:
Website: dazejs.org
Project address: github.com/dazejs/daze