Skip to content

Commit

Permalink
feat: 优化后端代码
Browse files Browse the repository at this point in the history
  • Loading branch information
wuranxu committed May 29, 2024
1 parent a5398a6 commit 8f80b12
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config/defaultSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const Settings: LayoutSettings & {
https?: boolean;
logo?: string;
apiUrl?: string;
backend?: boolean;
} = {
navTheme: 'light',
// 拂晓蓝
Expand All @@ -23,6 +24,7 @@ const Settings: LayoutSettings & {
iconfontUrl: '//at.alicdn.com/t/font_915840_kom9s5w2t6k.js',
apiUrl: 'api.pity.fun',
https: false,
backend: false,
};

export default Settings;
10 changes: 8 additions & 2 deletions src/consts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ import defaultSettings from "../../config/defaultSettings";
// }

// const dev = isDev()
const getApiUrl = () => {
if (defaultSettings.backend) {
return window.location.host
}
return defaultSettings.apiUrl
}

const getUrl = () => {
const prefix = defaultSettings.https ? 'https://' : 'http://'
return `${prefix}${defaultSettings.apiUrl}`
return `${prefix}${getApiUrl()}`
}

const URL = getUrl();

const getWss = () => {
const prefix = defaultSettings.https ? 'wss://' : 'ws://'
return `${prefix}${defaultSettings.apiUrl}`
return `${prefix}${getApiUrl()}`
}

const CONFIG = {
Expand Down

0 comments on commit 8f80b12

Please sign in to comment.