首页 > 解决方案 > Lumen API 响应在标头中返回错误的“内容类型”。仅在 Serverpilot/DigitalOcean 上

问题描述

我正在通过 DigitalOcean 上的 Serverpilot 运行我的生产和测试服务器。

我的最后一个 API 是用 Laravel 的 Lumen 编写的。我以前用过几次,从来没有遇到过这个问题。

顺便说一句,在我的本地环境中一切正常。(OS X。代客)

该应用程序是一个 API,它从 Webflows API 收集数据,将其存储在本地数据库中,并将其返回给调用 API 的方式。(为什么?我们需要针对不同的 CMS 进行格式化,而 Webflow 对请求有限制)

返回看起来像这样 return ResponseService::getResponse('success', $items, 200);

服务看起来像这样

public static function getResponse(string $status, iterable $payload, int $http_code)
    {
        return response()->json(
            [
                'status' => $status,
                'payload' => $payload
            ],
            $http_code,
            [
                'Content-type' => 'application/json'
            ]
        );
    }

...并且$items是对数据库的标准调用,雄辩$items = $site->collections()->where('_id', $collection_id)->first()->items()->metas($request->data)->paginate();

在 Postman 中运行请求时,我在标题中得到Content-type: text/html; charset=UTF-8. 如前所述,这仅在测试和生产服务器上。不在本地环境中。

我在这里做错了什么?

标签: phplaravellumen

解决方案


推荐阅读