Pārlūkot izejas kodu

添加 dotenv 组件用于支持.env 文件

程旭源 1 gadu atpakaļ
vecāks
revīzija
2c41773dd2

+ 6 - 1
admin_node/.eslintrc

@@ -1,4 +1,9 @@
 {
   "root": true,
-  "extends": "eslint-config-egg/typescript"
+  "extends": "eslint-config-egg/typescript",
+  "rules": {
+    "indent": "off",
+    "@typescript-eslint/indent": ["error", 4],
+    "@typescript-eslint/no-var-requires": 0
+  }
 }

+ 22 - 17
admin_node/config/config.default.ts

@@ -1,23 +1,28 @@
 import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
+require('dotenv').config(); // 加载dotenv配置文件用于支持 env
 
-export default (appInfo: EggAppInfo) => {
-  const config = {} as PowerPartial<EggAppConfig>;
-
-  // override config from framework / plugin
-  // use for cookie sign key, should change to your own and keep security
-  config.keys = appInfo.name + '_1687254724720_1708';
 
-  // add your egg config in here
-  config.middleware = [];
+export default (appInfo: EggAppInfo) => {
+    const config = {} as PowerPartial<EggAppConfig>;
+    // override config from framework / plugin
+    // use for cookie sign key, should change to your own and keep security
+    config.security = {
+        csrf: {
+            enable: process.env.SECURITY_CSRF ? process.env.SECURITY_CSRF === 'true' : true,
+        },
+    };
+    config.keys = appInfo.name + process.env.SECURITY_KEY || '_1687254724720_1708';
 
-  // add your special config in here
-  const bizConfig = {
-    sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
-  };
+    // add your egg config in here
+    config.middleware = [];
 
-  // the return config will combines to EggAppConfig
-  return {
-    ...config,
-    ...bizConfig,
-  };
+    // add your special config in here
+    const bizConfig = {
+        sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
+    };
+    // the return config will combines to EggAppConfig
+    return {
+        ...config,
+        ...bizConfig,
+    };
 };

+ 2 - 1
admin_node/package.json

@@ -26,14 +26,15 @@
     "@eggjs/tegg-eventbus-plugin": "^3.5.2",
     "@eggjs/tegg-plugin": "^3.5.2",
     "@eggjs/tegg-schedule-plugin": "^3.5.2",
+    "dotenv": "^16.3.1",
     "egg": "^3.15.0",
     "egg-scripts": "^2.17.0",
     "egg-tracer": "^2.0.0"
   },
   "devDependencies": {
+    "@eggjs/tsconfig": "1",
     "@types/mocha": "10",
     "@types/node": "18",
-    "@eggjs/tsconfig": "1",
     "egg-bin": "6",
     "egg-mock": "5",
     "eslint": "8",

+ 5 - 0
admin_node/yarn.lock

@@ -2068,6 +2068,11 @@ dot-prop@^4.2.0:
   dependencies:
     is-obj "^1.0.0"
 
+dotenv@^16.3.1:
+  version "16.3.1"
+  resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e"
+  integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==
+
 duplexer@~0.1.1:
   version "0.1.2"
   resolved "https://registry.yarnpkg.com/duplexer/-/duplexer-0.1.2.tgz#3abe43aef3835f8ae077d136ddce0f276b0400e6"