Skip to content

Commit

Permalink
fix: cache 没有 config 问题
Browse files Browse the repository at this point in the history
  • Loading branch information
winixt committed Nov 15, 2023
1 parent 2097234 commit 79091dc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 43 deletions.
1 change: 1 addition & 0 deletions packages/fes-plugin-request/src/template/cacheControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export default async (ctx, next) => {
const cacheData = getCacheData({ key: ctx.key, cacheType: config.cache.cacheType });
if (cacheData) {
ctx.response = {
config,
data: cacheData,
};
return;
Expand Down
81 changes: 39 additions & 42 deletions packages/fes-template-h5/src/app.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,43 @@
import { defineRuntimeConfig } from '@fesjs/fes';

export default defineRuntimeConfig({
// request: {},
request: {
baseURL: '/ras-mas',
dataHandler(data) {
console.log('data', data);
if (data?.code !== '0') {
if (data.code === '10000') {
console.log('code', data.code);
}
if (data?.code === '20000') {
console.log('code', data.code);
}
throw new Error(data);
}
return data.result ? data.result : data;
},
errorHandler(error) {
if (error.response) {
// 请求成功发出且服务器也响应了状态码,但状态代码超出了 2xx 的范围
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
} else if (error.request) {
// 请求已经成功发起,但没有收到响应
// `error.request` 在浏览器中是 XMLHttpRequest 的实例,
// 而在node.js中是 http.ClientRequest 的实例
console.log(error.request);
} else if (error.type) {
// 插件异常
console.log(error.msg);
} else {
// 发送请求时出了点问题
console.log('Error', error.message);
}
console.log('error', error.config);
},
},
patchRoutes: () => {
console.log('patchRoutes');
},
});

// export default defineRuntimeConfig({
// request: {
// baseURL: '/ras-mas',
// dataHandler(data) {
// if (data?.code !== '0') {
// if (data.code === '10000') {
// console.log('code', data.code);
// }
// if (data?.code === '20000') {
// console.log('code', data.code);
// }
// throw new Error(data);
// }
// return data.result ? data.result : data;
// },
// errorHandler(error) {
// if (error.response) {
// // 请求成功发出且服务器也响应了状态码,但状态代码超出了 2xx 的范围
// console.log(error.response.data);
// console.log(error.response.status);
// console.log(error.response.headers);
// } else if (error.request) {
// // 请求已经成功发起,但没有收到响应
// // `error.request` 在浏览器中是 XMLHttpRequest 的实例,
// // 而在node.js中是 http.ClientRequest 的实例
// console.log(error.request);
// } else if (error.type) {
// // 插件异常
// console.log(error.msg);
// } else {
// // 发送请求时出了点问题
// console.log('Error', error.message);
// }
// console.log(error.config);
// },
// },
// patchRoutes: () => {
// console.log('patchRoutes');
// },
// });
4 changes: 3 additions & 1 deletion packages/fes-template-h5/src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
</template>

<script setup>
import { defineRouteMeta } from '@fesjs/fes';
import { defineRouteMeta, request } from '@fesjs/fes';
defineRouteMeta({
title: '首页',
name: 'testIndex',
layout: false,
});
request('http://f1.test-adm.weoa.com/rcs-cscm/user/checkAlddddive.do');
</script>

0 comments on commit 79091dc

Please sign in to comment.