我是Lumen的新手。我開始在MAC OS上使用Lumen並在Docker容器中運行它。只看到流明POST API調用的應用版本
在dockerfile的應用服務如下:
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 (5.4.6) (Laravel Components 5.4.*)
現在我已經得到確認的API終點爲簡單的SMS。用戶應該從和發送電話號碼,我只是根據數據庫中的數據進行驗證並返回結果。
我routes.php文件寫着:
$app->post('/outbound/sms', 'App\Http\Controllers\[email protected]');
我SmsController是在應用程序\ HTTP \控制器現在。它使用一個PhoneNumber型號如下:
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\PhoneNumber;
use Illuminate\Support\Facades\App;
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.*)
即使將index.php附加到url也不起作用。 無法弄清楚什麼是錯的?
更新: 最後,我得到的路線工作正常。我的routes.php內容應該在routes/web.php而不是App \ Http中。
堅果現在我得到NotFoundHttpException。下面是堆棧跟蹤::
in RoutesRequests.php (line 594)
at Application->handleDispatcherResponse(array(0))
in RoutesRequests.php (line 532)
at Application->Laravel\Lumen\Concerns\{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)