mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-08-31 01:01:11 +08:00
feat(core): support .env file to config environment variables
This commit is contained in:
@@ -14,3 +14,4 @@ tmp
|
||||
*.swp
|
||||
*.iml
|
||||
coverage
|
||||
.env
|
||||
|
||||
@@ -82,15 +82,14 @@ $ git pull
|
||||
|
||||
`RSSHub` reads its configurations from `lib/config.js` or system environment variables.
|
||||
|
||||
**How to set system environment variables**
|
||||
Create a `.env` file in the root directory of your project. Add environment-specific variables on new lines in the form of `NAME=VALUE`. For example:
|
||||
|
||||
Under Windows, enter `$ set PORT=1000` in cmd
|
||||
```
|
||||
CACHE_TYPE=redis
|
||||
CACHE_EXPIRE=600
|
||||
```
|
||||
|
||||
Under UNIX-based OS, enter `$ PORT=1000` in terminal
|
||||
|
||||
Enter `$ npm start` to start a `RSSHub` install with port `1000`.
|
||||
|
||||
System environment variables set here will be purged after closing cmd/terminal, if you want persist the variables, you can create a simple [batch script](https://en.wikipedia.org/wiki/Batch_file) or [shell script](https://en.wikipedia.org/wiki/Shell_script).
|
||||
Please notice that it will not override already existed environment variables, more rules please refer to [dotenv](https://github.com/motdotla/dotenv)
|
||||
|
||||
To configure more options please refer to [Settings](#Settings).
|
||||
|
||||
|
||||
@@ -86,15 +86,14 @@ $ git pull
|
||||
|
||||
可以通过设置环境变量来配置 RSSHub.
|
||||
|
||||
**如何设置环境变量**
|
||||
在项目根目录新建一个 `.env` 文件,每行以 `NAME=VALUE` 格式添加环境变量,例如
|
||||
|
||||
Windows 系统在 cmd.exe 中运行 `$ set PORT=1000`
|
||||
```
|
||||
CACHE_TYPE=redis
|
||||
CACHE_EXPIRE=600
|
||||
```
|
||||
|
||||
macOS & Linux 运行 `$ PORT=1000`
|
||||
|
||||
再运行 `$ npm start` 启动 RSSHub 即可将监听端口设置为 `1000`.
|
||||
|
||||
此处设置的环境变量在关闭终端后就会被清除, 如果您想保存这些配置可以编写一个简单的 [批处理文件](https://en.wikipedia.org/wiki/Batch_file) 或 [shell](https://en.wikipedia.org/wiki/Shell_script).
|
||||
注意它不会覆盖已有的环境变量,更多规则请参考 [dotenv](https://github.com/motdotla/dotenv)
|
||||
|
||||
更多配置项请看 [应用配置](#应用配置)
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
require('dotenv').config();
|
||||
const config = require('./config');
|
||||
const Koa = require('koa');
|
||||
const fs = require('fs');
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
"co-redis": "2.1.1",
|
||||
"currency-symbol-map": "4.0.4",
|
||||
"dayjs": "1.8.13",
|
||||
"dotenv": "8.0.0",
|
||||
"etag": "1.8.1",
|
||||
"form-data": "2.3.3",
|
||||
"git-rev-sync": "1.12.0",
|
||||
|
||||
@@ -3550,6 +3550,11 @@ dot-prop@^4.1.0, dot-prop@^4.1.1:
|
||||
dependencies:
|
||||
is-obj "^1.0.0"
|
||||
|
||||
dotenv@8.0.0:
|
||||
version "8.0.0"
|
||||
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.0.0.tgz#ed310c165b4e8a97bb745b0a9d99c31bda566440"
|
||||
integrity sha512-30xVGqjLjiUOArT4+M5q9sYdvuR4riM6yK9wMcas9Vbp6zZa+ocC9dp6QoftuhTPhFAiLK/0C5Ni2nou/Bk8lg==
|
||||
|
||||
double-ended-queue@^2.1.0-0:
|
||||
version "2.1.0-0"
|
||||
resolved "https://registry.yarnpkg.com/double-ended-queue/-/double-ended-queue-2.1.0-0.tgz#103d3527fd31528f40188130c841efdd78264e5c"
|
||||
|
||||
Reference in New Issue
Block a user