{"id":13816450,"url":"https://github.com/phly/react2psr7","last_synced_at":"2025-07-23T16:35:34.350Z","repository":{"id":57039013,"uuid":"56447263","full_name":"phly/react2psr7","owner":"phly","description":"Serve PSR-7 middleware applications from a React HTTP server","archived":false,"fork":false,"pushed_at":"2016-04-18T14:57:19.000Z","size":24,"stargazers_count":39,"open_issues_count":0,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-01T18:12:12.271Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phly.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-17T16:41:53.000Z","updated_at":"2025-02-16T04:18:23.000Z","dependencies_parsed_at":"2022-08-24T00:51:05.089Z","dependency_job_id":null,"html_url":"https://github.com/phly/react2psr7","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phly%2Freact2psr7","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phly%2Freact2psr7/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phly%2Freact2psr7/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phly%2Freact2psr7/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phly","download_url":"https://codeload.github.com/phly/react2psr7/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253877265,"owners_count":21977632,"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-08-04T05:00:41.871Z","updated_at":"2025-05-13T04:33:17.787Z","avatar_url":"https://github.com/phly.png","language":"PHP","readme":"# react2psr7\n\n[![Build Status](https://secure.travis-ci.org/phly/react2psr7.svg?branch=master)](https://secure.travis-ci.org/phly/react2psr7)\n[![Coverage Status](https://coveralls.io/repos/github/phly/react2psr7/badge.svg?branch=master)](https://coveralls.io/github/phly/react2psr7?branch=master)\n\nServe PSR-7 middleware applications from [React](http://reactphp.org).\n\n## Installation\n\n```console\n$ composer require \"react/http:^0.5@dev\" phly/react2psr7\n```\n\n\u003e ### react/http\n\u003e\n\u003e react2psr7 currently requires features from the upcoming 0.5 release of\n\u003e react/http. Since that version is not yet released, you need to specify\n\u003e it manually when installing to force Composer to allow a development\n\u003e release.\n\n## Usage\n\nThe following demonstrates creating an HTTP server using React, and using an\n[Expressive](https://zendframework.github.io/zend-expressive/) application\nto handle incoming requests.\n\n```php\n\u003c?php\nuse React\\EventLoop\\Factory;\nuse React\\Http\\Server as HttpServer;\nuse React\\Socket\\Server as Socket;\nuse React2Psr7\\ReactRequestHandler;\nuse Zend\\Expressive\\Application;\n\nrequire_once 'vendor/autoload.php';\n\n$loop      = Factory::create();\n$socket    = new Socket($loop);\n$http      = new HttpServer($socket);\n$container = require 'config/container.php';\n\n$http-\u003eon('request', new ReactRequestHandler($container-\u003eget(Application::class)));\n\n// Listen on all ports; omit second argument to restrict to localhost.\n$socket-\u003elisten(1337, '0.0.0.0');\n$loop-\u003erun();\n```\n\n## Serving static files\n\nThis package also provides middleware for serving static files; this can be\nuseful when running React as a web server, to allow serving CSS, JavaScript, and\nimages.\n\nThe following demonstrates using [Stratigility](https://github.com/zendframework/zend-stratigility)\nto build a middleware pipeline that consumes both the static files middleware\nas well as an Expressive application in order to provide a full-fledged web\nserver.\n\n```php\n\u003c?php\nuse React\\EventLoop\\Factory;\nuse React\\Http\\Server as HttpServer;\nuse React\\Socket\\Server as Socket;\nuse React2Psr7\\ReactRequestHandler;\nuse React2Psr7\\StaticFiles;\nuse Zend\\Expressive\\Application;\nuse Zend\\Stratigility\\MiddlewarePipe;\n\nrequire_once 'vendor/autoload.php';\n\n$loop      = Factory::create();\n$socket    = new Socket($loop);\n$http      = new HttpServer($socket);\n$container = require 'config/container.php';\n$pipeline  = new MiddlewarePipe();\n\n$pipeline-\u003epipe(new StaticFiles());\n$pipeline-\u003epipe($container-\u003eget(Application::class));\n\n$http-\u003eon('request', new ReactRequestHandler($pipeline));\n\n// Listen on all ports; omit second argument to restrict to localhost.\n$socket-\u003elisten(1337, '0.0.0.0');\n$loop-\u003erun();\n```\n\n(Note: you could also pipe the static files middleware into your Expressive\napplication.)\n","funding_links":[],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphly%2Freact2psr7","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphly%2Freact2psr7","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphly%2Freact2psr7/lists"}