{"id":17445961,"url":"https://github.com/jamen/hyperserver","last_synced_at":"2025-06-26T02:33:18.070Z","repository":{"id":57120115,"uuid":"110318054","full_name":"jamen/hyperserver","owner":"jamen","description":"Tiny WebSocket server that hooks into Hyperapp","archived":false,"fork":false,"pushed_at":"2017-11-11T04:34:09.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-10T10:51:25.618Z","etag":null,"topics":[],"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/jamen.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":"2017-11-11T04:32:31.000Z","updated_at":"2021-12-19T15:35:42.000Z","dependencies_parsed_at":"2022-08-23T20:00:09.239Z","dependency_job_id":null,"html_url":"https://github.com/jamen/hyperserver","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jamen/hyperserver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamen%2Fhyperserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamen%2Fhyperserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamen%2Fhyperserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamen%2Fhyperserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamen","download_url":"https://codeload.github.com/jamen/hyperserver/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamen%2Fhyperserver/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261986647,"owners_count":23240677,"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":[],"created_at":"2024-10-17T18:18:58.484Z","updated_at":"2025-06-26T02:33:18.015Z","avatar_url":"https://github.com/jamen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# @jamen/hyperserver\n\n\u003e Tiny WebSocket server that hooks into Hyperapp\n\nProvdies a WebSocket server that hooks into Hyperapp actions.  It uses \"remote actions\", which are just actions that pass through a server first.  The different can be visualized as:\n\n```\nNormal action:\n\n    Action +---\u003e State +---\u003e View\n\n\nRemote action:\n\n    Action +- - - - - -Offline?- - - - - - -\u003e State +---\u003e View\n             \\                            /\n    (Servers) +---Request-----Response---+\n```\n\n## Install\n\n```\nnpm i -D @jamen/hyperserver\n```\n\n## Usage\n\n### `server(props)`\n\nCreates a WebSocket server with\n\n- `messages` handling each incomming action.\n- `host` being address of the server. (Defaults to `localhost`)\n- `port` being port of the server. (Defaults to `3001`)\n- `error(err)` being called\n\nEach message looks like `name(request, response)`.  They receive and send messages formated as `[name, data]`, which correlates to actions client-side.  For example:\n\n```js\nserver({\n  messages: {\n    token (req, res) {\n      // Receive \"token\" action from client\n      console.log(req.data)\n\n      // Respond with \"token\" action on client\n      res.send('token', {\n        token: randomBytes(8).toString('hex')\n      })\n    }\n  }\n})\n```\n\nSee below for handling responses.\n\n### `remote(app, options)`\n\nAn extension to Hyperapp which adds `props.remote` for specifying remote actions.  It connects to the Hyperserver with\n\n- `host` being the address of the server. (Defaults to `localhost`)\n- `port` being the port of the server. (Defaults to `3001`)\n\nRemote actions are like regular actions except they ask a server first.\n\n```\nAction +- - - - - -Offline?- - - - - - -\u003e State +---\u003e View\n         \\                            /\n(Servers) +---Request-----Response---+\n```\n\nAn example of using the extension:\n\n```js\napp = remote(app)\n\napp({\n  state: {\n    count: 0\n  },\n  remote: {\n    add: (state, actions) =\u003e data {\n      return { count: data.count + 1 }\n    }\n  },\n  view: (state, actions) =\u003e (\n    h('button', { onclick: actions.add }, state.count)\n  )\n})\n```\n\nEverything defined in `remote` is available as `actions` everywhere else.  Note remote actions take precedence of normal actions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamen%2Fhyperserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamen%2Fhyperserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamen%2Fhyperserver/lists"}