Quellcode durchsuchen

环境变量配置

Darkhorsedamon vor 2 Jahren
Ursprung
Commit
e3a59e9422
3 geänderte Dateien mit 17 neuen und 16 gelöschten Zeilen
  1. 10 10
      nuxt.config.js
  2. 4 3
      package.json
  3. 3 3
      plugins/localStorage.js

+ 10 - 10
nuxt.config.js

@@ -3,7 +3,7 @@
  * @Author: 欧阳承珺
  * @LastEditors: 欧阳承珺
  * @Date: 2022-10-17 11:06:52
- * @LastEditTime: 2022-11-16 11:28:15
+ * @LastEditTime: 2022-11-16 15:41:46
  */
 export default {
   // Global page headers: https://go.nuxtjs.dev/config-head
@@ -20,16 +20,15 @@ export default {
     ],
     link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
   },
-  
+  env: {
+    BASE_URL: process.env.BASE_URL,
+    NODE_ENV: process.env.NODE_ENV
+  },
   // Global CSS: https://go.nuxtjs.dev/config-css
   css: [
     '@/assets/main.scss',
     {src:'element-ui/lib/theme-chalk/index.css'},
   ],
-  server: {
-    host: '0.0.0.0',
-    port: 8082
-  },
   // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
   plugins: [
     '~/plugins/axios',
@@ -57,12 +56,13 @@ export default {
   ],
   axios: {
     timeout: 3000,
+    baseURL: process.env.BASE_URL,
     prefix: '/17pdf-backend-core/',
-    proxy: process.env.NODE_ENV !== 'production'
-  },
-  proxy: {
-    '/17pdf-backend-core': { target: 'http://81.68.234.235:8999',}
+    // proxy: process.env.NODE_ENV !== 'production'
   },
+  // proxy: {
+  //   '/17pdf-backend-core': { target: 'http://81.68.234.235:8999',}
+  // },
 
   // Build Configuration: https://go.nuxtjs.dev/config-build
   build: {

+ 4 - 3
package.json

@@ -3,9 +3,9 @@
   "version": "1.0.0",
   "private": true,
   "scripts": {
-    "dev": "nuxt",
-    "build": "nuxt build",
-    "start": "nuxt start",
+    "dev": "cross-env BASE_URL=http://81.68.234.235:8999 NODE_ENV=development nuxt",
+    "build": "cross-env BASE_URL=https://139.196.160.101:8864 NODE_ENV=production nuxt",
+    "start": "cross-env BASE_URL=https://139.196.160.101:8864 NODE_ENV=production nuxt",
     "generate": "nuxt generate",
     "lint:js": "eslint --ext \".js,.ts,.vue\" --ignore-path .gitignore .",
     "lint:prettier": "prettier --check .",
@@ -35,6 +35,7 @@
     "@nuxtjs/eslint-config-typescript": "^11.0.0",
     "@nuxtjs/eslint-module": "^3.1.0",
     "@nuxtjs/proxy": "^2.1.0",
+    "cross-env": "^7.0.3",
     "eslint": "^8.24.0",
     "eslint-config-prettier": "^8.5.0",
     "eslint-plugin-nuxt": "^4.0.0",

+ 3 - 3
plugins/localStorage.js

@@ -3,11 +3,11 @@
  * @Author: 欧阳承珺
  * @LastEditors: 欧阳承珺
  * @Date: 2022-10-26 09:30:22
- * @LastEditTime: 2022-11-16 13:54:28
+ * @LastEditTime: 2022-11-16 15:44:52
  */
 import createPersistedState from 'vuex-persistedstate'
 import * as Cookies from 'js-cookie'
-import cookie from 'cookie';
+import { cookieParse } from '~/utils/cookie'
 
 
 export default ({store, req}) => {
@@ -15,7 +15,7 @@ export default ({store, req}) => {
         storage: {
             getItem: (key) => {
                 if (process.server) {
-                    const parsedCookies = cookie.parse(req.headers.cookie);
+                    const parsedCookies = cookieParse(req.headers.cookie)
                     return parsedCookies[key];
                 } else {
                     return Cookies.get(key);