Files
vue-ts-example/fake/upload.fake.ts
严浩 5f0eaa2579
All checks were successful
/ build-and-deploy-to-vercel (push) Successful in 1m19s
/ depcheck (push) Successful in 1m19s
/ playwright (push) Successful in 3m28s
feat: 更新上传假数据处理逻辑,添加原始响应方法并支持选择禁用选项
2024-12-16 00:38:02 +08:00

35 lines
839 B
TypeScript

// fake/user.fake.ts
import { defineFakeRoute } from 'vite-plugin-fake-server/client';
let fail = !false;
export default defineFakeRoute([
{
timeout: 2000,
method: 'POST',
url: '/fake/upload',
/* response: (_, __, res) => {
fail = !fail;
if (fail) {
res.statusCode = 500;
return {
error: 'Upload failed',
};
}
return {
url: 'https://picsum.photos/200/300',
};
}, */
rawResponse(req, res) {
fail = !fail;
if (fail) {
res.writeHead(500, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ error: 'Upload failed' }));
} else {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ url: 'https://picsum.photos/200/300' }));
}
},
},
]);