【发布时间】:2018-05-12 13:24:24
【问题描述】:
我正在开发一个使用 Slim Framework v3 的应用程序,并且我正在尝试使用内置的 php 服务器来测试代码。 问题是无论我尝试什么,我仍然会收到 stock 404 错误消息。
我正在使用以下命令运行 Web 服务器:
php -S localhost:8080 src/routes/api.php
这是我在 api.php 中的代码
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: "GET, POST, PUT, PATCH, DELETE, OPTIONS"');
header('Access-Control-Allow-Headers: Authorization, X-Auth-Token, Content-Type');
require __DIR__ . '/../../vendor/autoload.php';
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
$settings = [
'settings' => [
'determineRouteBeforeAppMiddleware' => true,
'displayErrorDetails' => true
],
];
$app = new Slim\App($settings);
// Dependency injection
$di_container = $app->getContainer();
$app->get('/help', function (Request $request, Response $response, $args) {
return $response->withJson(['test']);
});
当我将 api.php 中的 /help 路由更改为简单的 / 然后访问浏览器中的任何路由时,我可以看到该 / 路由的结果。 有什么想法吗?
【问题讨论】:
-
尝试从路由目录启动php内部网络服务器:
cd src/routes和php -S localhost:8080 api.php。然后打开:http://localhost:8080/help -
已经试过了,还是不行