Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amphp/http-server-static-content
An HTTP server plugin to serve static files like HTML, CSS, JavaScript, and images effortlessly.
https://github.com/amphp/http-server-static-content
amphp document-root http http-server php revolt static-content static-files
Last synced: 3 months ago
JSON representation
An HTTP server plugin to serve static files like HTML, CSS, JavaScript, and images effortlessly.
- Host: GitHub
- URL: https://github.com/amphp/http-server-static-content
- Owner: amphp
- License: mit
- Created: 2018-03-12T00:02:59.000Z (almost 7 years ago)
- Default Branch: 2.x
- Last Pushed: 2024-01-23T08:29:01.000Z (about 1 year ago)
- Last Synced: 2024-05-01T09:51:38.580Z (9 months ago)
- Topics: amphp, document-root, http, http-server, php, revolt, static-content, static-files
- Language: PHP
- Homepage: https://amphp.org/http-server-static-content
- Size: 116 KB
- Stars: 21
- Watchers: 7
- Forks: 12
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# http-server-static-content
AMPHP is a collection of event-driven libraries for PHP designed with fibers and concurrency in mind. This package provides an [HTTP server](https://amphp.org/http-server) plugin to serve static files like HTML, CSS, JavaScript, and images effortlessly.
## Installation
This package can be installed as a [Composer](https://getcomposer.org/) dependency.
```bash
composer require amphp/http-server-static-content
```## Usage
This package provides two `RequestHandler` implementations:
- **`DocumentRoot`**: Serves all files within a directory.
- **`StaticResource`**: Serves a single specific file.The example below combines static file serving and [request routing](https://amphp.org/http-server-router) to demonstrate how they work well together:
```php
setFallback(new DocumentRoot($server, $errorHandler, __DIR__ . '/public'));
$router->addRoute('GET', '/', new ClosureRequestHandler(function () {
return new Response(Status::OK, ['content-type' => 'text/plain'], 'Hello, world!');
}));$server->start($router, new DefaultErrorHandler());
```A full example is found in [`examples/server.php`](https://github.com/amphp/http-server-static-content/blob/2.x/examples/server.php).
## Contributing
Please read [our rules](https://amphp.org/contributing) for details on our code of conduct, and the process for submitting pull requests to us.
## Security
If you discover any security related issues, please use the private security issue reporter instead of using the public issue tracker.
## License
The MIT License (MIT). Please see [LICENSE](./LICENSE) for more information.