dev-master
9999999-devPoa static file serving middleware.
MIT
The Requires
by York
react-php koa poa poa-middleware koa-static
0.1.0
0.1.0.0Poa static file serving middleware.
MIT
The Requires
by York
react-php koa poa poa-middleware koa-static
Wallogit.com
2017 © Pedro Peláez
Poa static file serving middleware.
![Software License][ico-license]
, (*1)
poa-static 是POA框架的一个中间件,用来处理静态文件的请求, (*2)
composer require york8/poa-static
$app = new Application();
$staticMiddleware = new StaticMiddleware('..');
$staticMiddleware->use(new ProfileMiddleware())->use(new SimpleFilenamePlugin('/static'));
// 定义路由器,将路径 /static 前缀开头的请求交给 StaticMiddleware 处理
$router = new RouterMiddleware(function (Context $context) {
$context->statusCode(404)->send('Not Found');
});
$router->get('/static', $staticMiddleware);
$app->useErrorMiddleware(function (Throwable $throwable) {
// 全局未捕获 错误/异常 处理
fwrite(STDERR, $throwable->getMessage() . "\n");
})
// 简单请求错误异常处理
->use(function (Context $context) {
try {
yield;
} catch (Throwable $exception) {
fwrite(STDERR, $exception->getMessage() . "\n");
$context->statusCode(500)->send($exception->getMessage());
}
})
// 使用路由器
->use($router);
$app->listen('0.0.0.0:8088');
The MIT License (MIT). Please see License File for more information., (*3)
Poa static file serving middleware.
MIT
react-php koa poa poa-middleware koa-static
Poa static file serving middleware.
MIT
react-php koa poa poa-middleware koa-static