Skip to content

Commit

Permalink
feat(core): support .env file to config environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed May 5, 2019
1 parent e775632 commit e0f39bd
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ tmp
*.swp
*.iml
coverage
.env
13 changes: 6 additions & 7 deletions docs/en/install/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Under UNIX-based OS, enter `$ PORT=1000` in terminal

Enter `$ npm start` to start a `RSSHub` install with port `1000`.
```
CACHE_TYPE=redis
CACHE_EXPIRE=600
```

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).

Expand Down
13 changes: 6 additions & 7 deletions docs/install/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,14 @@ $ git pull

可以通过设置环境变量来配置 RSSHub.

**如何设置环境变量**
在项目根目录新建一个 `.env` 文件,每行以 `NAME=VALUE` 格式添加环境变量,例如

Windows 系统在 cmd.exe 中运行 `$ set PORT=1000`

macOS & Linux 运行 `$ PORT=1000`

再运行 `$ npm start` 启动 RSSHub 即可将监听端口设置为 `1000`.
```
CACHE_TYPE=redis
CACHE_EXPIRE=600
```

此处设置的环境变量在关闭终端后就会被清除, 如果您想保存这些配置可以编写一个简单的 [批处理文件](https://en.wikipedia.org/wiki/Batch_file)[shell](https://en.wikipedia.org/wiki/Shell_script).
注意它不会覆盖已有的环境变量,更多规则请参考 [dotenv](https://github.com/motdotla/dotenv)

更多配置项请看 [应用配置](#应用配置)

Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('dotenv').config();
const config = require('./config');
const Koa = require('koa');
const fs = require('fs');
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit e0f39bd

Please sign in to comment.