Skip to content

Commit

Permalink
fix:cors
Browse files Browse the repository at this point in the history
  • Loading branch information
master1lan committed Jan 19, 2023
1 parent 81aa70b commit e6b9914
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 68 deletions.
2 changes: 1 addition & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ErrorPage from "./routers/error";
//preview
import ScreenProview from "@components/proview/screenSize";
import MUIThemePreview from "@components/proview/themePreview";
import SearchFocuspreview from "@components/proview/searchFocus";
import { Provider } from "react-redux";
import store from "@store/index";
//ployfill
Expand All @@ -16,7 +17,6 @@ import "./normalize.css";
import "loading-attribute-polyfill";
import "whatwg-fetch";
import "./index.less";
import SearchFocuspreview from "@components/proview/searchFocus";

const router = createBrowserRouter([
{
Expand Down
11 changes: 5 additions & 6 deletions src/utils/fetch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@
* 类型文件导入
*/
import { IFetchVideoParams, RFetchVideoRes } from "./fetchtype";
import { Host_Url } from "./tool";

/**
* video视频数据获取接口
*/
export function fetchVideos(
params: IFetchVideoParams
): Promise<RFetchVideoRes> {
const fetchUrl = `/v1/video-interface/advanced-search?order=${
const fetchUrl = `${Host_Url}/v1/video-interface/advanced-search?order=${
params.order || "score"
}&page=${params.page}${
params.copyright ? `&copyright=${params.copyright}` : ""
}
${params.q ? `&q=${params.q}` : ""}
${params.tname ? `&tname=${params.tname}` : ""}`
${
params.tname ? `&tname=${params.tname}` : ""
}&subscription-key=3cc4284fbb864965a7a9ad0f28af8496`
.replace(/\s+/g, "")
.trim();
return fetch(fetchUrl, {
method: "GET",
headers: {
"ocp-Apim-Subscription-Key": "3cc4284fbb864965a7a9ad0f28af8496",
origin: "https://portal.api.eoe.best",
},
}).then((response) => response.json() as Promise<RFetchVideoRes>);
}
1 change: 1 addition & 0 deletions src/utils/fetch/tool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const Host_Url = isdev ? "" : `https://api.eoe.best/eoefans-api`;
1 change: 1 addition & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/// <reference types="vite/client" />
declare const __APP_VERSION__: string;
declare const isdev: string;
126 changes: 65 additions & 61 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineConfig } from "vite";
import { defineConfig, loadEnv } from "vite";
import path from "path";
import react from "@vitejs/plugin-react-swc";
// 可视化打包文件
Expand All @@ -8,70 +8,74 @@ import viteCompression from "vite-plugin-compression";
// polyfill
import legacy from "@vitejs/plugin-legacy";
// https://vitejs.dev/config/
export default defineConfig({
define: {
__APP_VERSION__: "0.1",
},
resolve: {
alias: {
"@utils": path.resolve(__dirname, "src/utils"),
"@components": path.resolve(__dirname, "src/components"),
"@store": path.resolve(__dirname, "src/store"),
"@routers": path.resolve(__dirname, "src/routers"),
"@assets": path.resolve(__dirname, "src/assets"),

export default defineConfig(({ mode }) => {
return {
define: {
__APP_VERSION__: 0.01,
isdev: mode === "development",
},
},
plugins: [
react(),
legacy({
// 设置目标浏览器,browserslist 配置语法
targets: [
"defaults",
"iOS >= 9, Android >= 4.4, last 2 versions, > 0.2%, not dead",
],
}),
{ ...visualizer(), apply: "build" },
{ ...viteCompression(), apply: "build" },
],
build: {
// target: "es2015",
minify: "esbuild",
rollupOptions: {
output: {
manualChunks: {
react: ["react", "react-dom"],
"react-router": ["react-router-dom"],
"react-redux": ["@reduxjs/toolkit", "react-redux"],
lib: [
"@mui/icons-material",
"@mui/lab",
"@mui/material",
"@emotion/react",
"@emotion/styled",
],
"dnd-tool": [
"@dnd-kit/core",
"@dnd-kit/modifiers",
"@dnd-kit/sortable",
"@dnd-kit/utilities",
],
ployfill: [
"whatwg-fetch",
"intersection-observer",
"react-flip-toolkit",
"react-intersection-observer",
"dayjs",
],
resolve: {
alias: {
"@utils": path.resolve(__dirname, "src/utils"),
"@components": path.resolve(__dirname, "src/components"),
"@store": path.resolve(__dirname, "src/store"),
"@routers": path.resolve(__dirname, "src/routers"),
"@assets": path.resolve(__dirname, "src/assets"),
},
},
plugins: [
react(),
legacy({
// 设置目标浏览器,browserslist 配置语法
targets: [
"defaults",
"iOS >= 9, Android >= 4.4, last 2 versions, > 0.2%, not dead",
],
}),
{ ...visualizer(), apply: "build" },
{ ...viteCompression(), apply: "build" },
],
build: {
// target: "es2015",
minify: "esbuild",
rollupOptions: {
output: {
manualChunks: {
react: ["react", "react-dom"],
"react-router": ["react-router-dom"],
"react-redux": ["@reduxjs/toolkit", "react-redux"],
lib: [
"@mui/icons-material",
"@mui/lab",
"@mui/material",
"@emotion/react",
"@emotion/styled",
],
"dnd-tool": [
"@dnd-kit/core",
"@dnd-kit/modifiers",
"@dnd-kit/sortable",
"@dnd-kit/utilities",
],
ployfill: [
"whatwg-fetch",
"intersection-observer",
"react-flip-toolkit",
"react-intersection-observer",
"dayjs",
],
},
},
},
},
},
server: {
proxy: {
"/v1": {
target: "https://api.eoe.best/eoefans-api",
changeOrigin: true,
server: {
proxy: {
"/v1": {
target: "https://api.eoe.best/eoefans-api",
changeOrigin: true,
},
},
},
},
};
});

0 comments on commit e6b9914

Please sign in to comment.