Parcourir la source

添加 .env 文件, 服务端地址放到根据不同环境放到 env 文件中

reghao il y a 2 ans
Parent
commit
c76318b2de

+ 2 - 0
.env.development

@@ -0,0 +1,2 @@
+VUE_APP_SERVER_URL=//api.reghao.cn
+VUE_APP_OSS_URL=//oss.reghao.cn/

+ 2 - 0
.env.production

@@ -0,0 +1,2 @@
+VUE_APP_SERVER_URL=//api1.reghao.cn
+VUE_APP_OSS_URL=//oss1.reghao.cn/

+ 1 - 1
build.sh

@@ -1,6 +1,6 @@
 #!/bin/bash
 
-commit_id=`git rev-parse --short HEAD`
+commit_id=`git rev-parse HEAD | cut -c 1-8`
 npm run build
 docker build -t docker.reghao.cn/tnb/bili:${commit_id} .
 docker push docker.reghao.cn/tnb/bili:${commit_id}

+ 1 - 1
src/components/VideoPlayer.vue

@@ -23,7 +23,7 @@ export default {
       flvjs,
       DPlayer,
       danmaku: {
-        api: '//api.reghao.cn/api/comment/danmaku/',
+        api: process.env.VUE_APP_SERVER_URL + '/api/comment/danmaku/',
         token: 'bili'
       },
       getUrl: true

+ 2 - 1
src/components/card/TextCard.vue

@@ -7,7 +7,7 @@
       placeholder="有什么新鲜事想分享给大家?"
     />
     <el-upload
-      action="https://api.reghao.cn/api/content/timeline"
+      :action="actionUrl"
     >
       <el-button><i class="el-icon-picture-outline">图片</i></el-button>
     </el-upload>
@@ -25,6 +25,7 @@ export default {
   name: 'TextCard',
   data() {
     return {
+      actionUrl: process.env.VUE_APP_SERVER_URL + '/api/content/timeline',
       textarea: '',
       dialogImageUrl: '',
       dialogVisible: false

+ 1 - 1
src/components/layout/NavBar.vue

@@ -277,7 +277,7 @@ export default {
       this.$router.push(path)
     },
     register() {
-      window.open('//account.reghao.cn/login', '_blank')
+      console.log('帐号注册')
     },
     // ****************************************************************************************************************
     goToDisk() {

+ 2 - 1
src/components/upload/EditImage.vue

@@ -19,7 +19,7 @@
             </div>
             <div class="text item">
               <el-upload
-                action="//oss.reghao.cn/"
+                :action="actionUrl"
                 :headers="imgHeaders"
                 :data="imgData"
                 :file-list="uploadImages"
@@ -94,6 +94,7 @@ export default {
   name: 'EditImage',
   data() {
     return {
+      actionUrl: process.env.VUE_APP_OSS_URL,
       /** *********************************************************************/
       imgHeaders: {
         Authorization: ''

+ 3 - 2
src/components/upload/EditVideo.vue

@@ -21,7 +21,7 @@
               <el-tooltip class="item" effect="dark" content="点击上传图片" placement="top-end">
                 <el-upload
                   class="avatar-uploader"
-                  action="//oss.reghao.cn/"
+                  :action="actionUrl"
                   :headers="imgHeaders"
                   :data="imgData"
                   :with-credentials="true"
@@ -100,9 +100,10 @@ export default {
   name: 'EditVideo',
   data() {
     return {
+      actionUrl: process.env.VUE_APP_OSS_URL,
       // ****************************************************************************************************************
       options: {
-        target: '//oss.reghao.cn/',
+        target: process.env.VUE_APP_OSS_URL,
         chunkSize: 1024 * 1024 * 1024 * 5, // 5GiB
         fileParameterName: 'file',
         testChunks: false,

+ 1 - 1
src/components/upload/PublishAudio.vue

@@ -73,7 +73,7 @@ export default {
     return {
       // ****************************************************************************************************************
       options: {
-        target: '//oss.reghao.cn/',
+        target: process.env.VUE_APP_OSS_URL,
         chunkSize: 1024 * 1024 * 1024, // 1GiB
         fileParameterName: 'file',
         testChunks: false,

+ 3 - 2
src/components/upload/PublishFile.vue

@@ -35,7 +35,7 @@
             <el-tooltip class="item" effect="dark" content="点击上传图片" placement="top-end">
               <el-upload
                 class="avatar-uploader"
-                action="//oss.reghao.cn/"
+                :action="actionUrl"
                 :headers="imgHeaders"
                 :data="imgData"
                 :with-credentials="true"
@@ -81,9 +81,10 @@ export default {
   name: 'PublishFile',
   data() {
     return {
+      actionUrl: process.env.VUE_APP_OSS_URL,
       // ****************************************************************************************************************
       options: {
-        target: '//oss.reghao.cn/',
+        target: process.env.VUE_APP_OSS_URL,
         chunkSize: 1024 * 1024 * 1024 * 10, // 10GiB
         fileParameterName: 'file',
         testChunks: false,

+ 2 - 1
src/components/upload/PublishImage.vue

@@ -7,7 +7,7 @@
         </div>
         <div class="text item">
           <el-upload
-            action="//oss.reghao.cn/"
+            :action="actionUrl"
             :headers="imgHeaders"
             :data="imgData"
             :file-list="uploadImages"
@@ -72,6 +72,7 @@ export default {
   components: {},
   data() {
     return {
+      actionUrl: process.env.VUE_APP_OSS_URL,
       // ****************************************************************************************************************
       imgHeaders: {
         Authorization: ''

+ 4 - 3
src/components/upload/PublishVideo.vue

@@ -35,7 +35,7 @@
             <el-tooltip class="item" effect="dark" content="点击上传图片" placement="top-end">
               <el-upload
                 class="avatar-uploader"
-                action="//oss.reghao.cn/"
+                :action="actionUrl"
                 :headers="imgHeaders"
                 :data="imgData"
                 :with-credentials="true"
@@ -121,9 +121,10 @@ export default {
   name: 'PublishVideo',
   data() {
     return {
+      actionUrl: process.env.VUE_APP_OSS_URL,
       // ****************************************************************************************************************
       options: {
-        target: '//oss.reghao.cn/',
+        target: process.env.VUE_APP_OSS_URL,
         chunkSize: 1024 * 1024 * 1024 * 10, // 10GiB
         fileParameterName: 'file',
         testChunks: false,
@@ -338,7 +339,7 @@ export default {
           const formData = new FormData()
           formData.append('file', coverFile)
           formData.append('channelId', 5)
-          fetch(`//oss.reghao.cn/`, {
+          fetch(process.env.VUE_APP_OSS_URL, {
             headers: this.imgHeaders,
             method: 'POST',
             credentials: 'include',

+ 1 - 1
src/main.js

@@ -52,7 +52,7 @@ Vue.use(VueClipboards)
 import '@/permission'
 
 Vue.config.productionTip = false // 阻止控制台打印生产模式下的消息
-Vue.prototype.baseURL = '//api.reghao.cn'
+Vue.prototype.baseURL = process.env.VUE_APP_SERVER_URL
 new Vue({
   render: h => h(App),
   router,

+ 1 - 1
src/utils/request.js

@@ -6,7 +6,7 @@ import { getAccessToken, removeAll } from '@/utils/auth'
 
 const instance = axios.create({
   // 域名
-  baseURL: '//api.reghao.cn',
+  baseURL: process.env.VUE_APP_SERVER_URL,
   headers: {
     'Content-Type': 'application/json; charset=UTF-8'
   },

+ 1 - 1
src/utils/ws/socket-instance.js

@@ -20,7 +20,7 @@ class SocketInstance {
     this.socket = new WsSocket(
       () => {
         const token = getAccessToken()
-        var url = 'wss://api.reghao.cn/ws/progress?token=' + token
+        var url = 'wss:' + process.env.VUE_APP_SERVER_URL + '/ws/progress?token=' + token
         return url
       },
       {

+ 1 - 1
src/views/disk/UploadFile.vue

@@ -67,7 +67,7 @@ export default {
     return {
       // ****************************************************************************************************************
       options: {
-        target: '//oss.reghao.cn/',
+        target: process.env.VUE_APP_OSS_URL,
         chunkSize: 1024 * 1024 * 1024 * 10, // 10GiB
         fileParameterName: 'file',
         testChunks: false,

+ 1 - 1
src/views/home/Index.vue

@@ -143,7 +143,7 @@ export default {
     },
     initServerSendEvent() {
       if (typeof (EventSource) !== 'undefined') {
-        const sseUrl = 'https://api.reghao.cn/api/data/video/hot'
+        const sseUrl = process.env.VUE_APP_SERVER_URL + '/api/data/video/hot'
         const source = new EventSource(sseUrl)
         source.addEventListener('test', function(e) {
           console.log(e)

+ 1 - 1
src/views/home/MessageStream.vue

@@ -100,7 +100,7 @@ export default {
       this.text = ''
     },
     initWebSocket: function() {
-      var url = 'wss://api.reghao.cn/ws/log?token=1234567890'
+      var url = 'wss:' + process.env.VUE_APP_SERVER_URL + '/ws/log?token=1234567890'
       this.websock = new WebSocket(url)
       this.websock.onopen = this.websocketOnopen
       this.websock.onerror = this.websocketOnerror

+ 1 - 1
src/views/home/MessageStream1.vue

@@ -138,7 +138,7 @@ export default {
       this.text = ''
     },
     initWebSocket: function() {
-      var url = 'wss://api.reghao.cn/ws/message?token=11011'
+      var url = 'wss:' + process.env.VUE_APP_SERVER_URL + '/ws/message?token=11011'
       this.websock = new WebSocket(url)
       this.websock.onopen = this.websocketOnopen
       this.websock.onerror = this.websocketOnerror

+ 2 - 1
src/views/home/MessageStream2.vue

@@ -102,7 +102,8 @@ export default {
     init() {
       var list = this.dataList
       if (typeof (EventSource) !== 'undefined') {
-        const source = new EventSource('https://reghao.cn/times')
+        const url = process.env.VUE_APP_SERVER_URL + '/times'
+        const source = new EventSource(url)
         source.addEventListener('test', function(e) {
           console.log(e)
         })

+ 3 - 3
src/views/home/VideoList.vue

@@ -262,7 +262,7 @@ export default {
       props: {
         id: 114511,
         content: 'this is comment content',
-        imgSrc: '//oss.reghao.cn/image/a/41e5094eac724efeb2675eea22dd4468.jpg',
+        imgSrc: '',
         children: [],
         likes: 0,
         liked: false,
@@ -270,7 +270,7 @@ export default {
         createAt: 'createAt',
         user: {
           name: '芒果',
-          avatar: '//oss.reghao.cn/image/a/41e5094eac724efeb2675eea22dd4468.jpg'
+          avatar: ''
         }
       },
       // **********************************************************************/
@@ -309,7 +309,7 @@ export default {
       flvjs,
       DPlayer,
       danmaku: {
-        api: '//api.reghao.cn/api/comment/danmaku/',
+        api: process.env.VUE_APP_SERVER_URL + '/api/comment/danmaku/',
         token: 'bili'
       },
       getUrl: true

+ 2 - 2
src/views/home/VideoPage.vue

@@ -231,7 +231,7 @@ export default {
         {
           commentId: 114511,
           content: 'this is comment content',
-          imageUrl: '//oss.reghao.cn/image/a/41e5094eac724efeb2675eea22dd4468.jpg',
+          imageUrl: '',
           children: [],
           likes: 0,
           liked: false,
@@ -240,7 +240,7 @@ export default {
           user: {
             userId: 10001,
             name: '西瓜',
-            avatar: '//oss.reghao.cn/image/a/41e5094eac724efeb2675eea22dd4468.jpg'
+            avatar: ''
           }
         }
       ],

+ 1 - 1
src/views/login.vue

@@ -80,7 +80,7 @@ export default {
       this.dialogVisible = true
     },
     register() {
-      window.open('//account.reghao.cn/login', '_blank')
+      console.log('帐号注册')
     }
   }
 }

+ 4 - 0
src/views/my/My.vue

@@ -194,6 +194,10 @@ export default {
     if (userInfo !== null) {
       this.user = userInfo
     }
+
+    console.log(process.env)
+    console.log(process.env.VUE_APP_SERVER_URL)
+    console.log(process.env.VUE_APP_OSS_URL)
   }
 }
 </script>

+ 2 - 1
src/views/my/MyProfile.vue

@@ -10,7 +10,7 @@
             <el-tooltip class="item" effect="dark" content="点击更新我的头像" placement="top-end">
               <el-upload
                 class="avatar-uploader"
-                action="//oss.reghao.cn/"
+                :action="actionUrl"
                 :headers="imgHeaders"
                 :data="imgData"
                 :with-credentials="true"
@@ -60,6 +60,7 @@ export default {
   name: 'MyProfile',
   data() {
     return {
+      actionUrl: process.env.VUE_APP_OSS_URL,
       imgOssUrl: null,
       imgHeaders: {
         Authorization: ''