etherreq 1.2.7 → 1.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/index.ts
2
- import { request, baseURL as _baseURL, setBaseURL } from './request.js';
2
+ import { request, getBaseURL, setBaseURL, enableDebugMode, disableDebugMode } from './request.js';
3
3
  // 示例封装方法
4
4
  const createMethod = (method) => (url, data, callback) => {
5
5
  let options = { method }; // 修复:排除URL字段,明确指定method类型
@@ -59,4 +59,4 @@ export const etherreq = Object.assign((url, options, callback) => createMethod('
59
59
  }
60
60
  },
61
61
  });
62
- export { setBaseURL, _baseURL as baseURL };
62
+ export { setBaseURL, getBaseURL as baseURL, enableDebugMode, disableDebugMode };
package/dist/request.js CHANGED
@@ -101,13 +101,17 @@ export const request = (url, options = {}) => {
101
101
  else {
102
102
  finalURL = url;
103
103
  }
104
+ // 如果开启了调试模式,打印完整URL
105
+ if ((typeof process !== 'undefined' && process?.env?.NODE_ENV === 'development') || globalThis.__ETHERREQ_DEBUG__) {
106
+ console.log(`[etherreq] 发起${options.method || 'GET'}请求,完整URL: ${finalURL}`);
107
+ }
104
108
  return instance({
105
109
  url: finalURL, // 明确指定url属性
106
110
  ...options,
107
111
  });
108
112
  };
109
- // 导出 baseURL 供读取(只读)
110
- export const baseURL = _baseURL;
113
+ // 导出函数以获取当前的 baseURL
114
+ export const getBaseURL = () => _baseURL;
111
115
  // 允许外部设置全局 baseURL
112
116
  export const setBaseURL = (newBaseURL) => {
113
117
  if (typeof newBaseURL !== 'string' || newBaseURL.trim() === '') {
@@ -116,3 +120,10 @@ export const setBaseURL = (newBaseURL) => {
116
120
  }
117
121
  _baseURL = newBaseURL.trim();
118
122
  };
123
+ // 用于开启/关闭调试模式的函数
124
+ export const enableDebugMode = () => {
125
+ globalThis.__ETHERREQ_DEBUG__ = true;
126
+ };
127
+ export const disableDebugMode = () => {
128
+ globalThis.__ETHERREQ_DEBUG__ = false;
129
+ };
@@ -1,4 +1,4 @@
1
- import { baseURL as _baseURL, setBaseURL } from './request.js';
1
+ import { getBaseURL, setBaseURL, enableDebugMode, disableDebugMode } from './request.js';
2
2
  import type { EtherRequestOptions } from './types/cache.js';
3
3
  export declare const etherreq: ((url: string, options?: EtherRequestOptions, callback?: (error: Error | null, data: any) => void) => Promise<any>) & {
4
4
  get: (url: string, data?: any, callback?: (error: Error | null, data: any) => void) => Promise<any>;
@@ -11,4 +11,4 @@ export declare const etherreq: ((url: string, options?: EtherRequestOptions, cal
11
11
  patch: (url: string, data?: any, callback?: (error: Error | null, data: any) => void) => Promise<any>;
12
12
  login: (url: string, data?: any, callback?: (error: Error | null, data: any) => void) => Promise<any> | undefined;
13
13
  };
14
- export { setBaseURL, _baseURL as baseURL };
14
+ export { setBaseURL, getBaseURL as baseURL, enableDebugMode, disableDebugMode };
@@ -13,6 +13,8 @@ interface RequestConfigWithoutUrl {
13
13
  * @param options - 请求配置
14
14
  */
15
15
  export declare const request: (url: string, options?: RequestConfigWithoutUrl) => Promise<any>;
16
- export declare const baseURL: string;
16
+ export declare const getBaseURL: () => string;
17
17
  export declare const setBaseURL: (newBaseURL: string) => void;
18
+ export declare const enableDebugMode: () => void;
19
+ export declare const disableDebugMode: () => void;
18
20
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "etherreq",
3
- "version": "1.2.7",
3
+ "version": "1.2.8",
4
4
  "description": "A lightweight custom HTTP request library with TypeScript support.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -23,7 +23,7 @@
23
23
  "author": "guochang2635@icloud.com",
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
+ "@types/node": "^25.2.1",
26
27
  "typescript": "^5.0.0"
27
- },
28
- "dependencies": {}
29
- }
28
+ }
29
+ }