All Projects → polixjs → polix

polixjs / polix

Licence: MIT License
🚀 Node.js Web Framework

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to polix

Koatty
Koa2 + Typescript = Koatty. Use Typescript's decorator implement IOC and AOP.
Stars: ✭ 67 (+109.38%)
Mutual labels:  ioc, middleware, koa, koa2
Mysrv
Yet another Node.js web framework, based on koa.js 又一个 Node.js MVC 框架,基于Koa2
Stars: ✭ 10 (-68.75%)
Mutual labels:  koa, webframework, koa2
Vue Chat
👥Vue全家桶+Socket.io+Express/Koa2打造一个智能聊天室。
Stars: ✭ 887 (+2671.88%)
Mutual labels:  koa, koajs, koa2
koahub-cli
KoaHub CLI -- KoaHub.js的开发工具,自动babel编译 ES6/7(Generator Function, Class, Async & Await)并且文件修改后自动重启。
Stars: ✭ 16 (-50%)
Mutual labels:  koa, koajs, koa2
Koahub
KoaHub.js -- 中文最佳实践Node.js Web快速开发框架。支持Koa.js, Express.js中间件。当前项目已停止维护,推荐使用Doodoo.js
Stars: ✭ 308 (+862.5%)
Mutual labels:  koa, koajs, koa2
Koajs Design Note
《Koa.js 设计模式-学习笔记》已完结 😆
Stars: ✭ 520 (+1525%)
Mutual labels:  koa, koajs, koa2
Koach Javascript
Production ready Koa2 boilerplate.
Stars: ✭ 79 (+146.88%)
Mutual labels:  koa, koajs, koa2
Koa2 Note
《Koa2进阶学习笔记》已完结🎄🎄🎄
Stars: ✭ 4,725 (+14665.63%)
Mutual labels:  koa, koajs, koa2
Cool Admin Api
cool-admin-api 是基于egg.js、typeorm、jwt等封装的api开发脚手架、快速开发api接口
Stars: ✭ 188 (+487.5%)
Mutual labels:  koa, koajs, koa2
restria
Entria's REST API boilerplate
Stars: ✭ 25 (-21.87%)
Mutual labels:  koa, koajs, koa2
Koa Helmet
Important security headers for koa
Stars: ✭ 595 (+1759.38%)
Mutual labels:  middleware, koa, koa2
Koahub Demo
koahub+async/await+mysql
Stars: ✭ 15 (-53.12%)
Mutual labels:  koa, koajs, koa2
Sactive Web
🚀 A dependency injection web framework for Node.js.
Stars: ✭ 143 (+346.88%)
Mutual labels:  koa, webframework, koa2
Koa Hbs
Handlebars templates for Koa.js
Stars: ✭ 156 (+387.5%)
Mutual labels:  middleware, koa, koa2
Tsed
📐 Ts.ED is a Node.js and TypeScript framework on top of Express to write your application with TypeScript (or ES6). It provides a lot of decorators and guideline to make your code more readable and less error-prone.
Stars: ✭ 1,941 (+5965.63%)
Mutual labels:  ioc, middleware, koa
koa2-proxy
基于koa@next的代理工具,支持http和https,并且可以当做本地服务器使用
Stars: ✭ 42 (+31.25%)
Mutual labels:  koa, koa2
stack
A set of components for makers to ship better products faster 🚀
Stars: ✭ 27 (-15.62%)
Mutual labels:  koajs, koa2
firmeve
a out-of-the-box, full-featured go framework supporting http, http2, websocket, tcp, udp, rpc and microservice
Stars: ✭ 36 (+12.5%)
Mutual labels:  ioc, webframework
node-typescript-starter
REST API using Node with typescript, KOA framework. TypeORM for SQL. Middlewares JWT (auth), CORS, Winston Logger, Error, Response
Stars: ✭ 19 (-40.62%)
Mutual labels:  koa, koa2
koa-orm
koa orm using sequelize & sk2 (fork from knex)
Stars: ✭ 62 (+93.75%)
Mutual labels:  koajs, koa2

Polix

Node.js Web Framework

Travis Node Version npm

polix是基于koa v2.5.0的装饰器、插件式开发框架,和平常的Node.js Web Framework相比,它无需另外绑定路由集合、可拓展、开发简单,依照java的著名依赖注入框架spring来制作,让开发者专注于逻辑。polix采用多服务多进程架构来保证服务的稳定和快速响应能力。polix的中间件和koa v2.x的中间件保持兼容。polix提供Dockerfile+docker-compose.yml方案进行部署,默认使用的ORMsequelize(后续会提供polix-orm)。开发者可以选择ES6/7/8 或者 TypeScript来进行开发。

以上部分功能尚在开发阶段,敬请关注!

Install

NPM

$ npm i polix --save

Getting Started

使用polix-cli初始化应用

$ npm i polix-cli -g
$ pol init example
$ cd example
$ make build
$ make run-dev

Service

service文件夹下添加user.js

const { Service } = require('polix');

class UserService extends Service {
  constructor(){
    super();
    this._name = {};
  }

  async addUser(userId,name){
    this._name[userId] = name;
    return this;
  }

  async getUser(userId){
    return this._name[userId];
  }
}

module.exports = UserService;

Controller

controller文件夹下添加user.js

const { Controller, GET, POST, DEL, PUT  } = require('polix');

class UserController extends Controller {
  
  // POST /user/add�User
  @POST
  async addUser(param, ctx){
    const {body} = param;
    await this.service.user.addUser(body.userId, body.name);
    ctx.body = {
      result: 'ok'
    };
  }

  // GET /user/getUser
  @GET
  async getUser(param, ctx){
    const {query} = param;
    let user = await this.service.user.getUser(query.userId);
    ctx.body = {
      user
    };
  }

  // GET /user/info
  @GET('info')
  async getInfo(param, ctx){
    ctx.body = {
      v: 'v1.0'
    }
  }

  // PUT /user/updateUser
  @PUT
  async updateUser(param, ctx){
    ctx.body = {
      status: true
    }
  }

  // DEL /user/delUser
  @DEL
  async delUser(param, ctx){
    ctx.body = {
      status: true
    };
  }

  // GET /user/status/:userId
  @GET('status/:userId')
  async getStatus(param, ctx){
    const {router} = param;
    ctx.body = {
      status: true,
      userId: router.userId
    };
  }

}

module.exports = UserController;

Middware

polix的中间件与koa 2.x 的中间件保持兼容
框架默认加载koa-body中间件,如需另外添加中间件则新建middware文件夹(与controller文件夹平级)
添加跨域中间件 ,新建cors.js:

# cors.js

const cors = require('koa2-cors');
module.exports = function(){
  return cors({
    origin: function(ctx) {
      return '*';
    },
    exposeHeaders: ['WWW-Authenticate', 'Server-Authorization'],
    maxAge: 5,
    credentials: true,
    allowMethods: ['GET', 'POST', 'DELETE'],
    allowHeaders: ['Content-Type', 'Authorization', 'Accept']
  });
}

该文件夹下必须存在index.js文件作为总输出中间件文件,加载时根据导出对象的顺序进行绑定中间件

# index.js

const cors = require('./cors');

module.exports = {
    cors // 必须是函数 ,绑定方式为:app.use(cors())
}

Plugin

$ npm i --save polix-request

在项目根目录下的config文件夹下的plugin.default.js中添加以下代码

// `curl`最终会挂载到`this.app`下
exports.curl = {
  // 表示是否启用该插件
  enable: true,
  // 插件`npm`包名
  package: 'polix-request'
};

controller里用polix-request

  @GET
  async getWebInfo(param, ctx){
    let result = await this.app.curl.get('https://www.baidu.com');
    ctx.body = {
      data: result
    }
  }

polix已经内置polix-request插件了,这里只是个演示

Start

$ make dev

Author

Polix © Ricky 泽阳, Released under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].