{"id":15253553,"url":"https://github.com/st0ffern/koa-universal-relay-router","last_synced_at":"2026-05-07T06:39:52.879Z","repository":{"id":132733793,"uuid":"82538238","full_name":"st0ffern/koa-universal-relay-router","owner":"st0ffern","description":"Koa middleware for Universal/Isomorphic React + Relay rendering and routing","archived":false,"fork":false,"pushed_at":"2017-10-15T23:19:27.000Z","size":7,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-09T12:39:27.178Z","etag":null,"topics":["isomorphic","koa2","react","relay","router","universal","universal-javascript","webapp"],"latest_commit_sha":null,"homepage":null,"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/st0ffern.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":"2017-02-20T09:11:56.000Z","updated_at":"2023-03-11T12:20:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"e2ecb032-a6f6-464a-847f-93c1303bc65f","html_url":"https://github.com/st0ffern/koa-universal-relay-router","commit_stats":null,"previous_names":["stoffern/koa-universal-relay-router"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/st0ffern/koa-universal-relay-router","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/st0ffern%2Fkoa-universal-relay-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/st0ffern%2Fkoa-universal-relay-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/st0ffern%2Fkoa-universal-relay-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/st0ffern%2Fkoa-universal-relay-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/st0ffern","download_url":"https://codeload.github.com/st0ffern/koa-universal-relay-router/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/st0ffern%2Fkoa-universal-relay-router/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29892074,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-27T09:48:51.284Z","status":"ssl_error","status_checked_at":"2026-02-27T09:48:43.992Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["isomorphic","koa2","react","relay","router","universal","universal-javascript","webapp"],"created_at":"2024-09-29T21:05:26.030Z","updated_at":"2026-02-27T11:14:36.394Z","avatar_url":"https://github.com/st0ffern.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# koa-universal-relay-router\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/stoffern/koa-universal-relay-router.svg)](https://greenkeeper.io/)\nKoa middleware for Universal/Isomorphic React + Relay rendering and routing\n\n### Installation\n```js\nnpm i -S koa-universal-relay-router\n```\nor\n```js\nyarn add koa-universal-relay-router\n```\n\n###Usage\n#####client.js\n```js\nimport Relay from 'react-relay'\nimport {Router, browserHistory, applyRouterMiddleware } from 'react-router'\nimport useRelay from 'react-router-relay' \nimport {IsomorphicRelay, IsomorphicRouter} from 'koa-universal-relay-router'\n\nconst environment = new Relay.Environment();\nenvironment.injectNetworkLayer(\n    new Relay.DefaultNetworkLayer('http://example.com/graphql')\n)\n\n// Inject preloaded data from the server side\nconst data = JSON.parse(document.getElementById('preloaded-data').textContent);\nIsomorphicRelay.injectPreparedData(environment, data)\n\n// Find the root element\nconst rootElement = document.getElementById('root');\n\n// Use the same routes object as on the server\nmatch({ routes, history: browserHistory }, (error, redirectLocation, renderProps) =\u003e {\n  IsomorphicRouter.prepareInitialRender(environment, renderProps).then(props =\u003e {\n    ReactDOM.render(\n      \u003cRouter \n        history={browserHistory}\n        render={applyRouterMiddleware(useRelay)}\n        environment={Relay.Store}\n        {...props} \n      /\u003e\n    , rootElement);\n  });\n})\n```\n\n#####server.js\n```js\nimport Koa from 'koa'\nimport routes from './routes'\nimport Relay from 'react-relay'\nimport {renderServer} from 'koa-universal-relay-router'\n\nlet app = new Koa()\napp.use(renderServer({\n    networkLayer: new Relay.DefaultNetworkLayer('http://example.com/graphql'),\n    //or graphqlUrl: 'http://example.com/graphql',\n    routes: routes,\n    render: async (reactOutput, preloadedData, helmet) =\u003e {\n        return `\n            \u003c!DOCTYPE\u003e\n            \u003chtml\u003e\n                \u003chead\u003e\n                    \u003cmeta charset=\"utf-8\"\u003e\n                    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1\"\u003e\n                    ${helmet.title.toString()}\n                    ${helmet.meta.toString()}\n                    ${helmet.link.toString()}\n                \u003c/head\u003e\n                \u003cbody\u003e\n                    \u003cdiv id=\"root\"\u003e${reactOutput}\u003c/div\u003e\n                    \u003cscript id=\"preloaded-data\" type=\"application/json\"\u003e${preloadedData}\u003c/script\u003e\n                    \u003cscript src=\"app.js\"\u003e\u003c/script\u003e\n                \u003c/body\u003e\n            \u003c/html\u003e\n        `;\n    }\n}))\napp.listen(8080, () =\u003e {\n    console.log('Server is up')\n})\n```\n\n#### Props\n#####renderServer\n| Prop | Type | Description |\n|---|---|---|\n|**`routes`**|`react-routes`| Routes for naviation|\n|**`render`**|`function`|Function to render default client template|\n|**`networkLayer`**|`Relay NetworkLayer`|Send a custom Relay NetworkLayer into the router|\n|**`graphqlUrl`**|`string`|URI of the GraphQL API|\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fst0ffern%2Fkoa-universal-relay-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fst0ffern%2Fkoa-universal-relay-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fst0ffern%2Fkoa-universal-relay-router/lists"}