darukjs / daruk Goto Github PK
View Code? Open in Web Editor NEWa node.js web framework based on typescript
Home Page: http://darukjs.com
License: MIT License
a node.js web framework based on typescript
Home Page: http://darukjs.com
License: MIT License
A good and proper README might help people understand the goal of the project well. It is not necessary to be a word-to-word translation of the Chinese document.
https://darukjs.com/tutorial/about.html
Daruk, a typescript web framework.
example:
@get(/\/(foo|goo)/)
async foo(ctx: Daruk.Context) {
ctx.body = '';
}
ctx.request.body
will built in the framework
增加新features,@JSON 装饰器,只对controllerClass 适用。
https://darukjs.com/ecological/performance.html
Daruk, a typescript web framework.
darukConfig.middlewareOrder 中添加 koa-session 依赖后,controller 中使用 this.ctx.session.xxx,提示缺少 cookie 的 keys
darukConfig.middlewareOrder = [
'koa-handle-error',
'koa-favicon',
'koa-static',
'koa2-cors',
'koa-bodyparser',
'koa-test-mid',
'koa-art-template',
'koa-session',
'admin'
];
this.ctx.session.admin = { username, password };
Error: .keys required for signed cookies
at Cookies.set (/Users/apple/Desktop/study/daruk-demo/node_modules/cookies/index.js:109:27)
at ContextSession.save (/Users/apple/Desktop/study/daruk-demo/node_modules/koa-session/lib/context.js:338:22)
at ContextSession.commit (/Users/apple/Desktop/study/daruk-demo/node_modules/koa-session/lib/context.js:239:16)
at session (/Users/apple/Desktop/study/daruk-demo/node_modules/koa-session/index.js:46:20)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at koa-session (/Users/apple/Desktop/study/daruk-demo/node_modules/daruk/src/core/wrap_middleware_use.ts:16:5)
at koa-test-mid (/Users/apple/Desktop/study/daruk-demo/node_modules/daruk/src/core/wrap_middleware_use.ts:16:5)
at bodyParser (/Users/apple/Desktop/study/daruk-demo/node_modules/koa-bodyparser/index.js:73:48)
at koa-bodyparser (/Users/apple/Desktop/study/daruk-demo/node_modules/daruk/src/core/wrap_middleware_use.ts:16:5)
at cors (/Users/apple/Desktop/study/daruk-demo/node_modules/koa2-cors/dist/index.js:91:9)
class Index extends BaseController {
@required({
body:['foo'],
query:['bar'],
param:['id']
})
@post('/test/:id')
@get('/test/:id')
public index(ctx:Context, next: Function){
}
}
按照文档鼓捣了下,被配置卡住了,不知道什么含义,无法进行下一步。
能否完善一下文档。
Is it possible to add a uniform public version to the router, or use V1ContactList directly?
// src/controllers/contact/list.ts
import { BaseController, get, Context } from "daruk";
export default class V1ContactList extends BaseController {
@get("/")
public async getContactList(ctx: Context, next: Function) {
ctx.body = "contact list";
return next();
}
}
Is there any other way to achieve it? such as
// src/controllers/contact/list.ts
import { BaseController, get, Context, version } from "daruk";
@version('/v1')
export default class ContactList extends BaseController {
@get("/")
public async getContactList(ctx: Context, next: Function) {
ctx.body = "contact list";
return next();
}
}
Is your feature request related to a problem? Please describe.
按着默认配置是没法有上传文件的。
Describe the solution you'd like
需要在配置中加入 multipart true 才能开启
Describe alternatives you've considered
如果文档有说明就好了
Additional context
Add any other context or screenshots about the feature request here.
as build output, the build folder should not push to git repo
我是在win10下,使用vscode运行你的代码的。
Describe the bug
npm run dev 之后无法运行啊。
错误如下:
HuangGang@PC-20181118AWSO MINGW64 /d/DarukWorkSpace/daruk-example
$ npm run dev
[email protected] dev D:\DarukWorkSpace\daruk-example
cross-env NODE_ENV=dev nodemon --exec ts-node --files ./src/app.ts
rs
ts-node --files ./src/app.ts
[nodemon] app crashed - waiting for file changes before starting...
https://darukjs.com/tutorial/starup.html
Daruk, a typescript web framework.
https://darukjs.com/tutorial/decorator.html
Daruk, a typescript web framework.
No.
Describe the solution you'd like
Aspect Oriented Programming, like:
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
I think nest.js has more places to learn than koa.
Additional context
How to get url params like
@get('/:id')
// and then
ctx.params.id
utils support export default an object or function
@all-contributors please add @xiaojue for design
https://darukjs.com/tutorial/deploy.html
Daruk, a typescript web framework.
add feature:
@reDIrect with controller class method decorator.
Describe the bug
i want to kow how to develop this framework, by the way, there is only build script and i don't konw it works
Line 25 in 18daab0
Please enable all strict type-checking options.
基本上看了一遍文档,总体上感觉不错。但是有几个点我需要问下。
基于AOP的controller模式是否真的适用在架构中的问题其实一直以来都是有争论的。最早起源于java,Spring一整套都是基于AOP设计的路由。那么问题来了
我看到文档中有一些写法,我举个例子:
this.ctx.service.xxxxx
我知道这种模式来源于eggjs,但是这是eggjs的弊病之一。如果过多的模块中适用,会产生如下情况:
service.xxxx
的来源,只有本模块开发者知道,对于团队合作不利。至于glue
等,一样的道理。
容错对于一套架构来做很重要,在nodejs的服务架构中特别重要,因为在child_process
中错误捕获方式很多,我不清楚贵架构有没有做处理。我例举一些情况:
特别强调下请求丢失,有没有做请求的trace_id
,在全局容错中捕获请求错误同时让请求能够response。
比如说,daruk开启了多进程(cluster)模式,那么我现在有这样一个需求:我要编写一套基于进程隔离的自动打包前端代码的程序
npm run build
特点是每次打包开启一个新的进程进行隔离,那么在daruk中是否可以做到。因为在我看来,daruk没有涉及到自定义子进程模型,而仅仅是cluster模型。
以上是我的愚见。
in the official website
the only one example is:
// src/glues/mysql/index.ts
import { Daruk } from "daruk";
import mysql from "./connect";
export default function(daruk: Daruk) {
return mysql;
}
but in real production, my code is:
export default async function (daruk: Daruk) {
const mongodb = await mongoose.connect(dbUrl, {
useCreateIndex: true,
useNewUrlParser: true
})
const db = mongodb.connection
db.on('connected', () => {
debug(`Mongoose connection open to ${dbUrl}.`)
})
db.on('error', (err) => {
debug('Mongoose connection error: ' + err)
throw err
})
db.on('disconnected', () => {
debug('Mongoose connection disconnected')
})
return db
}
but I read the source code, I think this will run error
如何在DbTimer里面读取使用provide注册的Db
import { CronJob, Daruk, DarukServer, provide, inject, timer, TimerClass } from "daruk";
const main = async function () {
try {
const app = DarukServer();
@provide("Db")
class Db { }
@timer()
class DbTimer implements TimerClass {
@inject("Db") private Db!: Db;
public cronTime!: string;
public initTimer(daruk: Daruk) {
this.cronTime = '* * * * * *';
}
public onTick(cron: CronJob, daruk: Daruk) {
console.log(this.Db);
}
}
app.binding();
app.listen(8899);
} catch (error) {
console.log(error);
}
};
main(); // Error: No matching bindings found for serviceIdentifier: Db
as we all know, React.js have setState
to change states. and in our Daruk, how about when user code Daruk.itils.function1 = () => {}
and function1 have assigned
https://darukjs.com/tutorial/lifecycle.html
Daruk, a typescript web framework.
To Reproduce
npm install
or yarn install
In the docs, i find that the controllers are routers. Daruk will recursively read the files in the controllers directory, using the file name as the routing path.
If i want to deprecate or temporarily deprecate some routers, i must delete the routes in the corresponding controllers, even the whole controllers.
Is there any other elegant way to control routers or controller?Such as an ignore file, exclude flag or any other way.
提示:
'yarn' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
这个必须要用yarn吗?
是否有后续的迭代计划和 TODO
想贡献代码,有没有什么途径
I don't know if the vscode setting has other uses. At least we should remove the icon config because I have not installed the extension.
we can reference from
https://github.com/vuetifyjs/vuetify/blob/master/.travis.yml
Describe the bug
A clear and concise description of what the bug is.
koa-router is NOT
actively maintained. It may have bugs.
@koa/router
is a fork of it and has the same APIs. And it's developed by the official Koa team.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
Add any other context about the problem here.
Who is using Daruk in production?
// middleware/index.ts
export default function (daruk: Daruk) {
daruk.config.staticPath
}
// config.index.ts
import { Daruk } from 'daruk'
export default function (daruk: Daruk) {
return {
staticPath: 'xxx'
}
}
but display:
TS2339: Property 'staticPath' does not exist on type 'Config'
https://darukjs.com/tutorial/install.html#%E7%BC%96%E5%86%99-tsconfig-json-%E6%96%87%E4%BB%B6
Daruk, a typescript web framework.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.