feat: generate secure secret key and prevent default

This commit is contained in:
Lin, Hung-Shin authored and Annie Huang committed 2023-11-12 21:23:12 +08:00
1 parent 55b61dbcab
commit f1a50067c5
11 files changed
+45 -5

No files matched your search

+9 -2
View File
@@ -1,10 +1,10 @@
import { get } from './utils/env.js'
import { get, genSecret } from './utils/env.js'
const config = {
host: get('HOST', 'localhost'),
port: get('PORT', 3000),
db: get('MONGO_URL', 'mongodb://localhost:27017/odyssey-test'),
jwtSecret: get('JWT_SECRET', 'secret'),
secret: get('SECRET_KEY', ''),
dockerNetwork: get('DOCKER_NETWORK', 'linux-odyssey-players'),
isProduction: process.env.NODE_ENV === 'production',
hostPwd: get('HOST_PWD', ''),
@@ -22,4 +22,11 @@ const config = {
config.baseUrl = get('BASE_URL', `http://${config.host}:${config.port}`)
if (!config.secret) {
config.secret = genSecret()
console.warn(
'No SECRET_KEY found in .env! A temporary secret key has been generated. To set up a persistent key, please run the setup script.'
)
}
export default config