Match-id-a5f10cc817b40592611e27bb36f7d7e40bbdc80d
This commit is contained in:
commit
ff9eba84c1
File diff suppressed because it is too large
Load Diff
|
@ -24,9 +24,9 @@
|
|||
|
||||
sendRequestButton.addEventListener('click', function() {
|
||||
message.innerHTML = '';
|
||||
cancelTokenSource = horizonRequest.CancelToken.source();
|
||||
cancelTokenSource = inulaRequest.CancelToken.source();
|
||||
|
||||
horizonRequest.get('http://localhost:3001/data', {
|
||||
inulaRequest.get('http://localhost:3001/data', {
|
||||
cancelToken: cancelTokenSource.token
|
||||
}).then(function(response) {
|
||||
message.innerHTML = '请求成功: ' + JSON.stringify(response.data, null, 2);
|
||||
|
@ -36,15 +36,15 @@
|
|||
});
|
||||
|
||||
cancelRequestButton.addEventListener('click', function () {
|
||||
const CancelToken = horizonRequest.CancelToken;
|
||||
const CancelToken = inulaRequest.CancelToken;
|
||||
const source = CancelToken.source();
|
||||
|
||||
horizonRequest.get('http://localhost:3001/data', {
|
||||
inulaRequest.get('http://localhost:3001/data', {
|
||||
cancelToken: source.token
|
||||
}).then(function(response) {
|
||||
console.log(response.data);
|
||||
}).catch(function(error) {
|
||||
if (horizonRequest.isCancel(error)) {
|
||||
if (inulaRequest.isCancel(error)) {
|
||||
message.innerHTML = '请求已被取消:' + error.message;
|
||||
} else {
|
||||
message.innerHTML = '请求出错:' + error.message;
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Horizon Request Interceptor Test</title>
|
||||
<title>Inula Request Interceptor Test</title>
|
||||
<link rel="stylesheet" type="text/css" href="interceptorStyles.css">
|
||||
</head>
|
||||
<body>
|
||||
<header>Horizon Request interceptor Test</header>
|
||||
<header>Inula Request interceptor Test</header>
|
||||
<h2>使用拦截器:</h2>
|
||||
<div class="response-container">
|
||||
<h3>响应状态码:</h3>
|
||||
|
@ -89,7 +89,7 @@
|
|||
|
||||
// 不使用拦截器的请求
|
||||
document.getElementById('sendRequestWithoutInterceptor').addEventListener('click', function () {
|
||||
horizonRequest.get('http://localhost:3001/')
|
||||
inulaRequest.get('http://localhost:3001/')
|
||||
.then(function (response) {
|
||||
document.getElementById('responseStatusWithoutInterceptor').textContent = response.status;
|
||||
document.getElementById('responseDataWithoutInterceptor').textContent = JSON.stringify(response.data, null, 2);
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Horizon Request API Test</title>
|
||||
<title>Inula Request API Test</title>
|
||||
<link rel="stylesheet" type="text/css" href="requestStyles.css">
|
||||
</head>
|
||||
<body>
|
||||
<header>Horizon Request API Test</header>
|
||||
<header>Inula Request API Test</header>
|
||||
<div class="container">
|
||||
<div class="card">
|
||||
<h2>Request</h2>
|
||||
|
@ -85,8 +85,8 @@
|
|||
const resetButton = document.getElementById('resetButton');
|
||||
|
||||
queryButton.addEventListener('click', function () {
|
||||
const inulaRequest = inulaRequest.create();
|
||||
inulaRequest.request('http://localhost:3001/', {method: 'GET', data: {}})
|
||||
const irInstance = inulaRequest.create();
|
||||
irInstance.request('http://localhost:3001/', {method: 'GET', data: {}})
|
||||
.then(function (response) {
|
||||
requestResult.innerHTML = JSON.stringify(response.data, null, 2);
|
||||
})
|
||||
|
@ -189,7 +189,7 @@
|
|||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
horizonRequest.post('http://localhost:3001/', formData, {
|
||||
inulaRequest.post('http://localhost:3001/', formData, {
|
||||
onUploadProgress: function (progressEvent) {
|
||||
const loaded = progressEvent.loaded;
|
||||
const total = progressEvent.total;
|
||||
|
|
|
@ -23,12 +23,12 @@ app.use(cors(corsOptions));
|
|||
|
||||
// 处理 GET 请求
|
||||
app.get('/', (req, res) => {
|
||||
res.send('Hello Horizon Request!');
|
||||
res.send('Hello Inula Request!');
|
||||
})
|
||||
|
||||
app.get('/data', (req, res) => {
|
||||
const data = {
|
||||
message: 'Hello Horizon Request!',
|
||||
message: 'Hello Inula Request!',
|
||||
};
|
||||
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
|
@ -37,7 +37,7 @@ app.get('/data', (req, res) => {
|
|||
});
|
||||
|
||||
app.get('/download', (req, res) => {
|
||||
const filePath = 'D:\\code\\MRcode\\Horizon-Request\\examples\\request\\downloadTest.html';
|
||||
const filePath = 'D:\\code\\MRcode\\inula-Request\\examples\\request\\downloadTest.html';
|
||||
const fileName = 'downloadTest.html';
|
||||
const fileSize = fs.statSync(filePath).size;
|
||||
|
||||
|
|
|
@ -7,10 +7,10 @@ import { babel } from '@rollup/plugin-babel';
|
|||
export default {
|
||||
input: './index.ts',
|
||||
output: {
|
||||
file: 'dist/horizonRequest.js',
|
||||
file: 'dist/inulaRequest.js',
|
||||
format: 'umd',
|
||||
exports: 'named',
|
||||
name: 'horizonRequest',
|
||||
name: 'inulaRequest',
|
||||
sourcemap: false,
|
||||
},
|
||||
plugins: [
|
||||
|
|
|
@ -12,11 +12,17 @@ function processUploadProgress(
|
|||
) {
|
||||
if (onUploadProgress) {
|
||||
let totalBytesToUpload = 0; // 上传的总字节数
|
||||
|
||||
if (data instanceof File) {
|
||||
totalBytesToUpload = data.size;
|
||||
}
|
||||
if (data instanceof FormData) {
|
||||
data.forEach(value => {
|
||||
if (value instanceof Blob) {
|
||||
totalBytesToUpload += value.size;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const handleUploadProgress = () => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
|
|
|
@ -4,7 +4,7 @@ const path = require('path');
|
|||
// webpack配置信息
|
||||
module.exports = {
|
||||
// 指定入口文件
|
||||
entry: './src/horizonRequest.ts',
|
||||
entry: './src/inulaRequest.ts',
|
||||
|
||||
// 指定打包文件信息
|
||||
output: {
|
||||
|
@ -12,7 +12,7 @@ module.exports = {
|
|||
path: path.resolve(__dirname, 'dist'),
|
||||
library: 'myLibrary',
|
||||
libraryTarget: 'umd',
|
||||
filename: 'horizonRequest.js',
|
||||
filename: 'inulaRequest.js',
|
||||
},
|
||||
|
||||
// 指定打包时使用的模块
|
||||
|
|
Loading…
Reference in New Issue