仅查看带有流明开机自检API调用的应用程序版本



我是Lumen的新手。我开始在MAC OS上使用Lumen并在docker容器中运行它。

docker文件中的应用服务如下所示:

app:
build:
context: ./
dockerfile: app.dockerfile
working_dir: /var/www
volumes:
- ./:/var/www
environment:
- "DB_PORT=3306"
- "DB_HOST=database"

mysql服务也运行良好。打开 http://localhost:9002 我可以看到正常的 Lumen 应用程序版本控制:

Lumen (5.4.6) (Laravel Components 5.4.*)

现在,我已经为要确认的简单短信制作了一个 API 端点。用户应该发送来自和发送到电话号码,我只是根据数据库中存在的数据验证它们并返回结果。

我的路线.php是这样写的:

$app->post('/outbound/sms', 'AppHttpControllersSmsController@sendSms');

我的SmsController也出现在 App\Http\Controller 下。它使用电话号码模型,如下所示:

use IlluminateHttpRequest;
use AppHttpControllersController;
use AppPhoneNumber;
use IlluminateSupportFacadesApp;
public function sendSms(Request $request)
{
try
{
$fromModel = PhoneNumber::findOrFail($request->input('from'));
}
catch(ModelNotFoundException $e)
{
return response()->json(['message'=> '', 'error'=> 'from is not found']);
}
try
{
$toModel = PhoneNumber::findOrFail($request->input('to'));
}
catch(ModelNotFoundException $e)
{
return response()->json(['message'=> '', 'error'=> 'to is not found']);
}
$this->validateSms($_REQUEST);
return response()->json(['message'=> 'inbound sms ok', 'error'=> '']);
}

我的.htaccess文件显示:

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
Options +FollowSymLinks
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

在从邮递员进行 POST API 调用时,

http://localhost:9002/outbound/sms?from=1234567890&to=3456789&text=hi

我总是得到应用程序版本作为响应:

Lumen (5.4.6) (Laravel Components 5.4.*)

即使将索引.php附加到 url 也不起作用。 看不出出了什么问题?

更新:终于,我得到了路线工作正常。我的路由.php内容应该在路由/网络.php而不是 App\Http 中。

坚果现在我得到了NotFoundHttpException。以下是堆栈跟踪:

in RoutesRequests.php (line 594)
at Application->handleDispatcherResponse(array(0))
in RoutesRequests.php (line 532)
at Application->LaravelLumenConcerns{closure}()
in RoutesRequests.php (line 781)
at Application->sendThroughPipeline(array(), object(Closure))
in RoutesRequests.php (line 534)
at Application->dispatch(object(Request))
in RoutesRequests.php (line 475)
at Application->run(object(Request))
in index.php (line 29)

终于得到了 NotFoundHttpException 的原因:

在索引中添加了以下行.php:

$app = require __DIR__.'/../bootstrap/app.php';
$request = IlluminateHttpRequest::capture();
$app->run($request);

解决方案按照以下链接:

http://laravel-tricks.com/tricks/notfoundhttpexception-lumen。

对于任何偶然发现这个问题的人,请确保将您的路线保存在/routes/web.php中。

我遇到了同样的情况,为了使用 REST API 的 Lumen,将路由从应用程序/路由移动到路由/网络.php.php对我有用。它不需要我更改索引.php。

最新更新