From 550feffc825b6fd7a06339e132a55cdc31934f0b Mon Sep 17 00:00:00 2001 From: qq_59556663 Date: Mon, 30 Oct 2023 09:32:32 +0800 Subject: [PATCH] Auto Commit --- .inscode | 4 ++++ src/utils/https.ts | 21 +++++++++++++++++++++ src/utils/interceptors.ts | 26 ++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 src/utils/https.ts create mode 100644 src/utils/interceptors.ts diff --git a/.inscode b/.inscode index 70c7853..9fec957 100644 --- a/.inscode +++ b/.inscode @@ -1,4 +1,5 @@ run = "npm i && npm run dev" +language = "node" [deployment] build = "npm i && npm run build" @@ -8,3 +9,6 @@ run = "npm run preview" PATH = "/root/${PROJECT_DIR}/.config/npm/node_global/bin:/root/${PROJECT_DIR}/node_modules/.bin:${PATH}" XDG_CONFIG_HOME = "/root/.config" npm_config_prefix = "/root/${PROJECT_DIR}/.config/npm/node_global" + +[debugger] +program = "main.js" diff --git a/src/utils/https.ts b/src/utils/https.ts new file mode 100644 index 0000000..2bfc724 --- /dev/null +++ b/src/utils/https.ts @@ -0,0 +1,21 @@ +import { + AXIOS +} from './interceptors'; +export const method = { + get(addr: string) { + return AXIOS.get(addr); + }, + post(addr: string, datas: { [key: string]: any }) { + return AXIOS.post(addr, + datas, + ); + }, + put(addr: string, datas: { [key: string]: any }) { + return AXIOS.put(addr, { + ...datas, + }); + }, + delete(addr: string, id: number | string) { + return AXIOS.delete(`${addr}/${id}`); + } +} diff --git a/src/utils/interceptors.ts b/src/utils/interceptors.ts new file mode 100644 index 0000000..44a04e1 --- /dev/null +++ b/src/utils/interceptors.ts @@ -0,0 +1,26 @@ +import axios from "axios"; + +export const AXIOS = axios.create({ + // baseURL: "/login/api", + baseURL: "" +}) + +AXIOS.interceptors.request.use( + function(response: any) { + response.headers["Authorization"] = sessionStorage.getItem("token"); + return response; + }, + function(error) { + console.log(error) + return false; + } +) + +AXIOS.interceptors.response.use( + function(request) { + return request.data + }, + function(error) { + return Promise.reject(error); + } +) \ No newline at end of file -- GitLab