Skip to content

Commit

Permalink
feat: add dotenv
Browse files Browse the repository at this point in the history
  • Loading branch information
lazzzis committed Dec 25, 2021
1 parent a101f89 commit 4589ad3
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 27 deletions.
7 changes: 7 additions & 0 deletions .env
@@ -0,0 +1,7 @@
# production env

secretKey='Putong Putong Putong'
dbURL='mongodb://127.0.0.1:27017/oj'
redisURL='redis://127.0.0.1:6379'

PORT=3000
3 changes: 3 additions & 0 deletions .env.development
@@ -0,0 +1,3 @@
# development env extends production env

PORT = 8888
5 changes: 5 additions & 0 deletions .env.test
@@ -0,0 +1,5 @@
# test env extends production env

dbURL='mongodb://127.0.0.1:27017/testoj'

PORT=8888
3 changes: 0 additions & 3 deletions .gitignore
Expand Up @@ -100,9 +100,6 @@ typings/
# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
Expand Down
3 changes: 1 addition & 2 deletions app.js
@@ -1,5 +1,4 @@
const dotenv = require('dotenv')
dotenv.load()
require('dotenv-flow').config()

const Koa = require('koa')
const koaLogger = require('koa-logger')
Expand Down
2 changes: 2 additions & 0 deletions complete.js
@@ -1,3 +1,5 @@
require('dotenv-flow').config()

const Solution = require('./models/Solution')
const Problem = require('./models/Problem')
require('./config/db')
Expand Down
24 changes: 7 additions & 17 deletions config/index.js
Expand Up @@ -42,16 +42,13 @@ config.encrypt = {
}

config.deploy = {
judgers: 1,
judgers: 2,
adminInitPwd: 'kplkplkpl'
}

config.secretKey = process.env.secretKey || 'Putong Putong Putong'
config.secretKey = process.env.secretKey

config.dbURL = process.env.DBURL || process.env.dbURL || 'mongodb://127.0.0.1:27017/oj' // 之所以两个只为了兼容旧版命名;请优先采用后者
if (process.env.NODE_ENV === 'test') {
config.dbURL = 'mongodb://127.0.0.1:27017/testoj'
}
config.dbURL = process.env.DBURL || process.env.dbURL // 之所以两个只为了兼容旧版命名;请优先采用后者

config.mail = {
enable: true, // set false to disable email notifications
Expand All @@ -65,15 +62,8 @@ config.mail = {
}
}

const dev = {
port: 8888
}

const prod = {
port: 3000
}

module.exports = Object.assign(
process.env.NODE_ENV === 'production' ? prod : dev,
config
config.port = Number.parseInt(
process.env.PORT
)

module.exports = config
2 changes: 2 additions & 0 deletions manage.js
@@ -1,3 +1,5 @@
require('dotenv-flow').config()

const { resolve } = require('path')
const fse = require('fs-extra')
const range = require('lodash.range')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -17,7 +17,7 @@
"license": "MIT",
"dependencies": {
"cross-env": "^5.1.3",
"dotenv": "^6.0.0",
"dotenv-flow": "^3.2.0",
"fs-extra": "^5.0.0",
"ioredis": "^3.2.2",
"koa": "^2.4.1",
Expand Down
2 changes: 2 additions & 0 deletions services/mailer.js
@@ -1,3 +1,5 @@
require('dotenv-flow').config()

const nodemailer = require('nodemailer')
const config = require('../config')
const Discuss = require('../models/Discuss')
Expand Down
2 changes: 2 additions & 0 deletions services/node-0/judger.js
Expand Up @@ -8,6 +8,8 @@
* 6. 更新用户的 Submit 和 Solve
* 7. 结束,再次从第一步开始
*/
require('dotenv-flow').config()

const fse = require('fs-extra')
const { resolve } = require('path')
const shell = require('shelljs')
Expand Down
2 changes: 2 additions & 0 deletions services/updater.js
@@ -1,3 +1,5 @@
require('dotenv-flow').config()

require('../config/db')
const Solution = require('../models/Solution')
const Contest = require('../models/Contest')
Expand Down
15 changes: 11 additions & 4 deletions yarn.lock
Expand Up @@ -1740,10 +1740,17 @@ dot-prop@^4.2.0, dot-prop@^4.2.1:
dependencies:
is-obj "^1.0.0"

dotenv@^6.0.0:
version "6.2.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-6.2.0.tgz#941c0410535d942c8becf28d3f357dbd9d476064"
integrity sha512-HygQCKUBSFl8wKQZBSemMywRWcEDNidvNbjGVyZu3nbZ8qq9ubiPoGLMdRDpfSrpkkm9BXYFkpKxxFX38o/76w==
dotenv-flow@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/dotenv-flow/-/dotenv-flow-3.2.0.tgz#a5d79dd60ddb6843d457a4874aaf122cf659a8b7"
integrity sha512-GEB6RrR4AbqDJvNSFrYHqZ33IKKbzkvLYiD5eo4+9aFXr4Y4G+QaFrB/fNp0y6McWBmvaPn3ZNjIufnj8irCtg==
dependencies:
dotenv "^8.0.0"

dotenv@^8.0.0:
version "8.6.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.6.0.tgz#061af664d19f7f4d8fc6e4ff9b584ce237adcb8b"
integrity sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==

dottie@^2.0.0:
version "2.0.2"
Expand Down

0 comments on commit 4589ad3

Please sign in to comment.