Kaynağa Gözat

接口指向https

13127578837 1 yıl önce
ebeveyn
işleme
e7d66c4528
4 değiştirilmiş dosya ile 20 ekleme ve 15 silme
  1. 2 2
      package.json
  2. 0 2
      server.js
  3. 7 7
      src/components/layout/header.vue
  4. 11 4
      src/utils/request.ts

+ 2 - 2
package.json

@@ -5,8 +5,8 @@
     "type": "module",
     "scripts": {
         "dev": "vite",
-        "dev:ssr": "cross-env NODE_ENV=development  node server",
-        "prod:ssr": "cross-env NODE_ENV=production  node server",
+        "dev:ssr": "cross-env NODE_ENV=development  --ssr node server",
+        "prod:ssr": "cross-env NODE_ENV=production  --ssr node server",
         "build": "vue-tsc && vite build",
         "preview": "vite preview",
         "build:client": "vite build --outDir dist/client --ssrManifest",

+ 0 - 2
server.js

@@ -36,7 +36,6 @@ async function createServer() {
         let html
         try {
             if(!isProd){
-                console.log("开启开发服务端渲染")
                  // 1. 读取 index.html
                 template = fs.readFileSync(
                     path.resolve(__dirname, 'index.html'),
@@ -59,7 +58,6 @@ async function createServer() {
                 // const runtime = await vite.createViteRuntime(server)
                 // const { render } = await runtime.executeEntrypoint('/src/entry-server.ts')
             }else{
-                console.log("开启生产服务端渲染")
                 template = fs.readFileSync(
                     path.resolve(__dirname, 'dist/client/index.html'),
                     'utf-8',

+ 7 - 7
src/components/layout/header.vue

@@ -43,13 +43,13 @@ if(typeof window !== 'undefined' && typeof window.globalThis.addEventListener ==
         }
     });
     //百度统计
-    // var _hmt:any = _hmt || [];
-    // (function() {
-    // var hm = document.createElement("script");
-    // hm.src = "https://hm.baidu.com/hm.js?082d841c5adb911dd14595d0885a7c69";
-    // var s:any = document.getElementsByTagName("script")[0]; 
-    // s.parentNode.insertBefore(hm, s);
-    // })();
+    var _hmt:any = _hmt || [];
+    (function() {
+    var hm = document.createElement("script");
+    hm.src = "https://hm.baidu.com/hm.js?082d841c5adb911dd14595d0885a7c69";
+    var s:any = document.getElementsByTagName("script")[0]; 
+    s.parentNode.insertBefore(hm, s);
+    })();
 }
 </script>
 <template>

+ 11 - 4
src/utils/request.ts

@@ -1,16 +1,23 @@
 import axios, { InternalAxiosRequestConfig, AxiosResponse } from 'axios'
 import { tansParams } from './common.ts'
 // 创建axios实例
+console.log(import.meta.env)
+var url = "https://gateWay.usky.cn/"
+if (typeof window !== 'undefined'){
+    if(window.location.host.indexOf("localhost") > -1 || window.location.host.indexOf("172.16.120.165") >-1){
+        url = "http://172.16.120.165:13200/"
+    }
+    if(window.location.host.indexOf("usky.cn") > -1){
+        url = "https://gateWay.usky.cn/"
+    }
+}
 const service: any = axios.create({
     // axios中请求配置有baseURL选项,表示请求URL公共部分
-    baseURL: import.meta.env.PROD ? 'http://gateWay.usky.cn/' : "http://172.16.120.165:13200/",
-    // baseURL: import.meta.env.PROD ? 'http://gateWay.usky.cn/' : "http://172.16.120.165:13200/",
-    // baseURL: import.meta.env.PROD ? 'http://172.16.120.165:13200/' : "http://localhost:5173",
+    baseURL: url,
     // 超时
     timeout: 300000
 })
 
-
 // request拦截器
 service.interceptors.request.use((config: InternalAxiosRequestConfig) => {
     // 是否需要防止数据重复提交