Open JUNHAN12138 opened 11 months ago
我在umi框架里写的api接口怎么改请求里的response headers里的contentType为application/json
`import type { UmiApiRequest, UmiApiResponse } from "umi"; import fs from "fs"; import path from "path";
export default async function (req: UmiApiRequest, res: UmiApiResponse) { switch (req.method) { case "GET": try { const { id } = req.body; const mdxPath = path.join( process.cwd(), "src/mdxFile", ${20231127}.mdx );
${20231127}.mdx
const mdxContent = fs.readFileSync(mdxPath, "utf8"); res .status(200) .header("Content-Type", "application/json") .json({ content: mdxContent }); } catch { res.status(500).header("Content-Type", "application/json").json({ result: false, message: "报错", }); } break;
} }`
请求的接口response一直是这个 导致fetch的res.json()报错,
我在umi框架里写的api接口怎么改请求里的response headers里的contentType为application/json
`import type { UmiApiRequest, UmiApiResponse } from "umi"; import fs from "fs"; import path from "path";
export default async function (req: UmiApiRequest, res: UmiApiResponse) { switch (req.method) { case "GET": try { const { id } = req.body; const mdxPath = path.join( process.cwd(), "src/mdxFile",
${20231127}.mdx
);} }`
请求的接口response一直是这个 导致fetch的res.json()报错,