GithubHelp home page GithubHelp logo

darukjs / daruk Goto Github PK

View Code? Open in Web Editor NEW
936.0 33.0 79.0 1.78 MB

a node.js web framework based on typescript

Home Page: http://darukjs.com

License: MIT License

JavaScript 1.31% TypeScript 96.40% Smarty 1.68% Shell 0.61%
nodejs typescript node-framework

daruk's People

Contributors

alex1504 avatar allcontributors[bot] avatar chaslui avatar chersquwn avatar dependabot[bot] avatar dxil avatar himself65 avatar icepy avatar imakan avatar kenyeec avatar myluluy avatar myywlc avatar nawbc avatar xiaojue avatar xiaoqiang1999 avatar yiliang114 avatar youjingyu avatar zgayjjf avatar zheaoli avatar zhmushan avatar zuigzm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

daruk's Issues

Proper README in English

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.

设置 koa-session 时提示需要 keys

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)

[Feature] @required() decorator

class Index extends BaseController {
  @required({
     body:['foo'],
     query:['bar'],
     param:['id']
  })
  @post('/test/:id')
  @get('/test/:id')
  public index(ctx:Context, next: Function){
      
  }
}

文档不完善

按照文档鼓捣了下,被配置卡住了,不知道什么含义,无法进行下一步。

能否完善一下文档。

Router version(controller version)

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.

你好,我按照你的教程安装,但是无法运行。

我是在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

[nodemon] 1.19.0
[nodemon] to restart at any time, enter rs
[nodemon] watching: .
[nodemon] starting ts-node --files ./src/app.ts
[2019-5-5 17:25:22] [debug] [init] [config]
[2019-5-5 17:25:22] [debug] [init] [util] ["testUtil","sort"]
[2019-5-5 17:25:22] [debug] [init] [glue] ["mysql"]
[2019-5-5 17:25:22] [debug] [init] [middleware] ["koa-handle-error","koa-favicon","koa-static","koa-bodyparser","koa-test-mid","koa-ejs"]
[2019-5-5 17:25:22] [debug] AssertionError [ERR_ASSERTION]: controller class name should be
'\contact\index' ( CamelCase style and match route path ) in path: D:\DarukWorkSpace\daruk-example\src\controllers\contact\index.ts
at routers.forEach (D:\DarukWorkSpace\daruk-example\node_modules\daruk\src\core\daruk_loader.ts:112:7)
at Array.forEach ()
at DarukLoader.loadController (D:\DarukWorkSpace\daruk-example\node_modules\daruk\src\core\daruk_loader.ts:92:13)
at DarukCore.initEnv (D:\DarukWorkSpace\daruk-example\node_modules\daruk\src\core\daruk_init_module.ts:73:12)
at new DarukCore (D:\DarukWorkSpace\daruk-example\node_modules\daruk\src\core\daruk_core.ts:96:10)
at Object. (D:\DarukWorkSpace\daruk-example\src\daruk.init.ts:11:16)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Module.m._compile (D:\DarukWorkSpace\daruk-example\node_modules\ts-node\src\index.ts:439:23)
at Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Object.require.extensions.(anonymous function) [as .ts] (D:\DarukWorkSpace\daruk-example\node_modules\ts-node\src\index.ts:442:12)
logType: daruk-example
env: dev
fileinfo: \node_modules\daruk\src\core\daruk_core.ts:239:21
msg: process is exiting
os_hostname: PC-20181118AWSO
level: info
timestamp: 1557048322594

logType: daruk-example
env: dev
fileinfo: \node_modules\daruk\src\core\daruk_core.ts:243:21
msg: process exited: 1
os_hostname: PC-20181118AWSO
level: info
timestamp: 1557048322598

[nodemon] app crashed - waiting for file changes before starting...

How to get url params

Additional context
How to get url params like

@get('/:id')

// and then

ctx.params.id

关于daruk的一些建议

基本上看了一遍文档,总体上感觉不错。但是有几个点我需要问下。

AOP模型

基于AOP的controller模式是否真的适用在架构中的问题其实一直以来都是有争论的。最早起源于java,Spring一整套都是基于AOP设计的路由。那么问题来了

  1. java的路由不是compose模型,可以根据特征识别路由优先级,那么在daruk中,如何通过KOA2保证路由顺序?
  2. 之前我有测试过通过fastify与koa+koa-router的QPS数据,请看这里 ,那么在上述请看下,daruk能保证多少qps?(建议:find-my-way)

变量污染

我看到文档中有一些写法,我举个例子:

this.ctx.service.xxxxx

我知道这种模式来源于eggjs,但是这是eggjs的弊病之一。如果过多的模块中适用,会产生如下情况:

  1. 容易重复覆盖(当然我不知道有没有做override)
  2. 找不到service.xxxx的来源,只有本模块开发者知道,对于团队合作不利。
  3. 无法定义自有service等对象,因为被系统占用。

至于glue等,一样的道理。

容错机制

容错对于一套架构来做很重要,在nodejs的服务架构中特别重要,因为在child_process中错误捕获方式很多,我不清楚贵架构有没有做处理。我例举一些情况:

  1. 断网
  2. 语法错误
  3. 进程奔溃
  4. 请求丢失
  5. ......等等

特别强调下请求丢失,有没有做请求的trace_id,在全局容错中捕获请求错误同时让请求能够response。

特殊业务模型

比如说,daruk开启了多进程(cluster)模式,那么我现在有这样一个需求:我要编写一套基于进程隔离的自动打包前端代码的程序

  1. 我开启一个新进程,独立处理当前打包任务。
  2. 打包时候调用npm run build
  3. 需要将编译信息通过socket打出到前端页面(通过cluster的websocket输出)
  4. 打包结束关闭进程。

特点是每次打包开启一个新的进程进行隔离,那么在daruk中是否可以做到。因为在我看来,daruk没有涉及到自定义子进程模型,而仅仅是cluster模型。

最后

以上是我的愚见。

[Question] How to deal with async funciton?

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

如何在timer里面读取provide注册的类

如何在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

[Question] Is there any other elegant way to control router?

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.

remove vscode settings

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.

建议更换koa-router为@koa/router

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:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

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):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

[BUG] incorrect type on Config

// 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'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.