{"id":14989422,"url":"https://github.com/polixjs/polix","last_synced_at":"2026-02-18T13:01:52.829Z","repository":{"id":96173558,"uuid":"137732086","full_name":"polixjs/polix","owner":"polixjs","description":" 🚀 Node.js Web Framework","archived":false,"fork":false,"pushed_at":"2019-11-26T09:52:20.000Z","size":37,"stargazers_count":32,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T21:02:21.505Z","etag":null,"topics":["docker","http","ioc","koa","koa2","koajs","middleware","nodejs","plugin","polix","rpc","typescript","web","webframework"],"latest_commit_sha":null,"homepage":"https://polix.js.org","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/polixjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-18T09:18:29.000Z","updated_at":"2021-06-03T09:04:25.000Z","dependencies_parsed_at":"2023-05-09T09:46:37.935Z","dependency_job_id":null,"html_url":"https://github.com/polixjs/polix","commit_stats":{"total_commits":22,"total_committers":2,"mean_commits":11.0,"dds":"0.045454545454545414","last_synced_commit":"cbc978dc3207b9c95c22ca2df8584bb5431d2384"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polixjs%2Fpolix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polixjs%2Fpolix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polixjs%2Fpolix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polixjs%2Fpolix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/polixjs","download_url":"https://codeload.github.com/polixjs/polix/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248501420,"owners_count":21114674,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","http","ioc","koa","koa2","koajs","middleware","nodejs","plugin","polix","rpc","typescript","web","webframework"],"created_at":"2024-09-24T14:18:20.749Z","updated_at":"2026-02-18T13:01:52.796Z","avatar_url":"https://github.com/polixjs.png","language":"JavaScript","readme":"# Polix\n\nNode.js Web Framework\n\n[![Travis](https://img.shields.io/travis/polixjs/polix.svg?style=for-the-badge)](https://travis-ci.org/polixjs/polix)\n[![Node Version](https://img.shields.io/badge/node-%3E=9.0.0-brightgreen.svg?longCache=true\u0026style=for-the-badge)](https://www.npmjs.com/package/polix)\n[![npm](https://img.shields.io/npm/v/polix.svg?style=for-the-badge)](https://www.npmjs.com/package/polix)\n\n\n`polix`是基于`koa v2.5.0`的装饰器、插件式开发框架,和平常的`Node.js Web Framework`相比，它无需另外绑定路由集合、可拓展、开发简单，依照`java`的著名依赖注入框架`spring`来制作，让开发者专注于逻辑。`polix`采用多服务多进程架构来保证服务的稳定和快速响应能力。`polix`的中间件和`koa v2.x`的中间件保持兼容。`polix`提供`Dockerfile`+`docker-compose.yml`方案进行部署，默认使用的`ORM`是`sequelize`(后续会提供`polix-orm`)。开发者可以选择ES6/7/8 或者 TypeScript来进行开发。\n\n\u003e 以上部分功能尚在开发阶段，敬请关注！\n\n## Install \n\n[![NPM](https://nodei.co/npm/polix.png?compact=true)](https://nodei.co/npm/polix/)\n\n```bash\n$ npm i polix --save\n```\n\n## Getting Started\n\u003e 使用`polix-cli`初始化应用\n``` bash\n$ npm i polix-cli -g\n$ pol init example\n$ cd example\n$ make build\n$ make run-dev\n```\n\n## Service\n\u003e 在`service`文件夹下添加`user.js`\n\n```javascript\nconst { Service } = require('polix');\n\nclass UserService extends Service {\n  constructor(){\n    super();\n    this._name = {};\n  }\n\n  async addUser(userId,name){\n    this._name[userId] = name;\n    return this;\n  }\n\n  async getUser(userId){\n    return this._name[userId];\n  }\n}\n\nmodule.exports = UserService;\n```\n\n## Controller\n\u003e 在`controller`文件夹下添加`user.js`\n\n```javascript\nconst { Controller, GET, POST, DEL, PUT  } = require('polix');\n\nclass UserController extends Controller {\n  \n  // POST /user/add\bUser\n  @POST\n  async addUser(param, ctx){\n    const {body} = param;\n    await this.service.user.addUser(body.userId, body.name);\n    ctx.body = {\n      result: 'ok'\n    };\n  }\n\n  // GET /user/getUser\n  @GET\n  async getUser(param, ctx){\n    const {query} = param;\n    let user = await this.service.user.getUser(query.userId);\n    ctx.body = {\n      user\n    };\n  }\n\n  // GET /user/info\n  @GET('info')\n  async getInfo(param, ctx){\n    ctx.body = {\n      v: 'v1.0'\n    }\n  }\n\n  // PUT /user/updateUser\n  @PUT\n  async updateUser(param, ctx){\n    ctx.body = {\n      status: true\n    }\n  }\n\n  // DEL /user/delUser\n  @DEL\n  async delUser(param, ctx){\n    ctx.body = {\n      status: true\n    };\n  }\n\n  // GET /user/status/:userId\n  @GET('status/:userId')\n  async getStatus(param, ctx){\n    const {router} = param;\n    ctx.body = {\n      status: true,\n      userId: router.userId\n    };\n  }\n\n}\n\nmodule.exports = UserController;\n```\n\n## Middware\n`polix`的中间件与koa 2.x 的中间件保持兼容  \n框架默认加载`koa-body`中间件，如需另外添加中间件则新建`middware`文件夹（与`controller`文件夹平级）  \n添加跨域中间件 ，新建`cors.js`:  \n```javascript\n# cors.js\n\nconst cors = require('koa2-cors');\nmodule.exports = function(){\n  return cors({\n    origin: function(ctx) {\n      return '*';\n    },\n    exposeHeaders: ['WWW-Authenticate', 'Server-Authorization'],\n    maxAge: 5,\n    credentials: true,\n    allowMethods: ['GET', 'POST', 'DELETE'],\n    allowHeaders: ['Content-Type', 'Authorization', 'Accept']\n  });\n}\n```\n该文件夹下必须存在`index.js`文件作为总输出中间件文件,加载时根据导出对象的顺序进行绑定中间件\n\n```javascript\n# index.js\n\nconst cors = require('./cors');\n\nmodule.exports = {\n    cors // 必须是函数 ,绑定方式为：app.use(cors())\n}\n```\n\n## Plugin\n```shell\n$ npm i --save polix-request\n```\n\u003e 在项目根目录下的`config`文件夹下的`plugin.default.js`中添加以下代码\n```js\n// `curl`最终会挂载到`this.app`下\nexports.curl = {\n  // 表示是否启用该插件\n  enable: true,\n  // 插件`npm`包名\n  package: 'polix-request'\n};\n```\n\u003e 在`controller`里用`polix-request`\n```js\n  @GET\n  async getWebInfo(param, ctx){\n    let result = await this.app.curl.get('https://www.baidu.com');\n    ctx.body = {\n      data: result\n    }\n  }\n```\n\u003e `polix`已经内置`polix-request`插件了，这里只是个演示\n\n## Start\n\n```bash\n$ make dev\n```\n\n## Author\nPolix © [Ricky 泽阳](https://github.com/rickyes), Released under the MIT License.  \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolixjs%2Fpolix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolixjs%2Fpolix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolixjs%2Fpolix/lists"}