Files
vue-ts-example/fake/upload.fake.ts
严浩 511f07f778
All checks were successful
/ build-and-deploy-to-vercel (push) Successful in 1m39s
/ depcheck (push) Successful in 1m36s
/ playwright (push) Successful in 1m59s
feat: 优化假数据上传逻辑,简化响应处理并添加调试信息
2024-12-16 00:54:28 +08:00

27 lines
684 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: () => {
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' }));
}
},
},
]);