{"id":21045351,"url":"https://github.com/ymzuiku/serral","last_synced_at":"2026-05-20T10:15:17.648Z","repository":{"id":44814858,"uuid":"151259986","full_name":"ymzuiku/serral","owner":"ymzuiku","description":"完全使用Websocket代替http的Nodejs-Server 并且内置路由规则，简单且高性能 \\ Like Serral in StarCraft2, simple and direct powerful. Only websocket serve,  no http API.","archived":false,"fork":false,"pushed_at":"2018-11-04T18:25:47.000Z","size":1844,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-23T03:47:07.125Z","etag":null,"topics":["nodejs","router","server","uwebsockets","websocket"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ymzuiku.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-02T13:35:15.000Z","updated_at":"2022-07-12T06:52:53.000Z","dependencies_parsed_at":"2022-07-13T11:10:25.769Z","dependency_job_id":null,"html_url":"https://github.com/ymzuiku/serral","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ymzuiku/serral","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ymzuiku%2Fserral","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ymzuiku%2Fserral/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ymzuiku%2Fserral/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ymzuiku%2Fserral/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ymzuiku","download_url":"https://codeload.github.com/ymzuiku/serral/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ymzuiku%2Fserral/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263861994,"owners_count":23521357,"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":["nodejs","router","server","uwebsockets","websocket"],"created_at":"2024-11-19T14:21:42.886Z","updated_at":"2026-05-20T10:15:12.619Z","avatar_url":"https://github.com/ymzuiku.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Use [uWebSockets](https://github.com/uNetworking/uWebSockets) like http-server in Nodejs\n\n- Very tiny, only use [uWebSocket](https://github.com/uNetworking/uWebSockets) do Micro Service;\n- Client use `ws.fetch(uri)` call server router files;\n- Easy extends options in router;\n- Use very fast Log system, use [pino](http://getpino.io/#/);\n- Auto reconnet WebSocket;\n- Long time auto close WebSocket;\n- Like Serral in StarCraft2, simple and direct powerful.\n\n## Look Demo\n\nThis way is easy run example, just copy this code in your Terminal:\n\n```\ngit clone -b master --single-branch https://github.com/ymzuiku/serral\ncd serral\nyarn install \u0026\u0026 clear\nnode example/serve.js \u0026 sleep 0.5 \u0026\u0026 open example/client.html\n```\nWaiting `git clone` and `npm install` , if server runing, look Terminal and Browser like this:\n\n![](.imgs/2018-10-02-23-10-37.png)\n\nThe Web is at 30ms emit socket server;\n\n## Install\n\n```\n$ npm i --save serral\n# or\n$ yarn add -D serral\n```\n\n## Get Started\n\nYou can look example/serve.js and example/client.html\n\n### In client:\n\nIf you use React or Vue, add code in `src/index.js`\n\n```js\nimport serralClient from 'serral/client';\nconst ws = serralClient('ws://127.0.0.1:4000');\nws.onopen = function() {\n  ws.fetch(\n    'hello',\n    {\n      name: 'client: hello-server',\n      age: 200,\n    },\n    res =\u003e {\n      console.log('catch-server-message:', res);\n    },\n  );\n};\n```\n\n### In server:\n\nserver/index.js\n\n```js\nconst serral = require('serral');\nconst path = require('path');\n\n// auto load routers/xxx.js and router/xxx/index.js;\n// ignore underline begins files, like: _xxx.js\nserral.load(path.resolve(__dirname, 'routers'));\nserral.listen(4000);\n```\n\nserver/routers/hello.js\n\n```js\nmodule.exports = function(data, ws) {\n  console.log(data);\n  // if set uri, client can run wsCallback[uri] function\n  ws.json({ uri:data.uri, name: 'server:hello-client', age: 100 });\n};\n```\n\nRun serve:\n\n```sh\nnode server/index.js\n```\n\n## Load routers  rule:\n\nUse `serral.load('dir-path')`, serral can auto load files in directory:\n- If file return a `function`, serral use the file name like router path.\n- If file return a `{ obj }`, serral use file.objName.objName... until obj is function\n- If the 'file' is Directory, serral use require(file/index.js)\n- Ignore underline begins files, like: _xxx.js\n\nThis's example:\n\nServer\n\nserver/index.js\n\n```js\nconst serral = require('serral');\nconst path = require('path');\nserral.load(path.resolve(__dirname, 'routers'));\nserral.listen(4000);\n```\nserver/routers/login.js\n\n```js\nmodule.exports = {\n  // In client: ws.fetch('login.useEmail');\n  useEmail: function(data, ws, opts) {\n    // ws.json({ uri:data.uri, ...})\n  },\n  sendEmail: {\n    // In client: ws.fetch('login.sendEmail.changePassword');\n    changePassword: function(data, ws, opts) {\n      // ws.json({ uri:data.uri, ...})\n    },\n    bindEmail: {\n      // In client: ws.fetch('login.sendEmail.bindEmail.bindNow');\n      bindNow: function(data, ws, opts) {\n        // ws.json({ uri:data.uri, ...})\n      },\n    },\n  },\n};\n```\n\nClient\n\n```js\nimport serralClient from 'serral/client';\nconst ws = serralClient('ws://127.0.0.1:4000');\nws.onopen = function() {\n  // load server routers/login.js function\n  ws.fetch('login.useEmail');\n  ws.fetch('login.sendEmail.changePassword');\n  ws.fetch('login.sendEmail.bindEmail.bindNow');\n};\n```\n\n## Extends: If use mysql or other package\n\nServer:\n\nserver/index.js\n\n```js\nconst serral = require('../serve');\nconst Sequelize = require('sequelize');\nconst { resolve } = require('path');\n\nconst sequelize = new Sequelize('test', 'root', '111Asd', { dialect: 'mysql' });\nsequelize.authenticate();\n\n// Extends { db: sequelize } to opts\nserral.use({ db: sequelize });\n// serral.use() need before serral.load()\nserral.load(resolve(__dirname, 'routers'));\nserral.listen(4000);\n```\n\nserver/routers/hello.js\n\n```js\n// sequelize is extends in opts\nmodule.exports = function(data, ws, opts) {\n  console.log(opts); // { db: sequelize }\n  // use opts.db do someting\n};\n```\n\n## Use local log files\n\nIf you set `logPath`, log save in local file, use [pino](https://github.com/pinojs/pino)\n\n```js\nconst serral = require('../serve');\nconst path = require('path');\n\n// need ensure the existence of logPath\nserral.use({ logPath: path.resolve(__dirname, 'logs') });\n// serral.use() need before serral.load()\nserral.load(path.resolve(__dirname, 'routers'));\nserral.listen(4000);\n```\n\n## Use WebSocket replace to uWebSockets\n\nserral default use uWebSockets, but it's remove in npm.org. serral keep use uws@10.148.1. if you need use WebSocket replace to uWebSockets, you can use `lib: 'ws'` :\n\n```js\nconst serral = require('../serve');\nconst path = require('path');\nserral.use({ lib: 'ws' });\nserral.load(path.resolve(__dirname, 'routers'));\nserral.listen(4000);\n```\n\n## API setting live\n\n![](.imgs/2018-10-02-22-47-35.png)\n\n\n## Licenes\n\n```\nMIT License\n\nCopyright (c) 2013-present, Facebook, Inc.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fymzuiku%2Fserral","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fymzuiku%2Fserral","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fymzuiku%2Fserral/lists"}