feat: specify trust proxies

This commit is contained in:
Lin, Hung-Shin committed 2023-11-02 12:11:15 +08:00
1 parent a5896e7c15
commit 14043b3f12
7 files changed
+32 -7

No files matched your search

+12
View File
@@ -1,5 +1,16 @@
import validator from 'validator'
import { get } from './utils/env.js'
function getTrustProxies(key) {
if (!process.env[key]) {
return []
}
return process.env[key]
.split(',')
.map((p) => validator.trim(p))
.filter((p) => validator.isIPRange(p) || validator.isIP(p))
}
const config = {
host: get('HOST', 'localhost'),
port: get('PORT', 3000),
@@ -18,6 +29,7 @@ const config = {
clientID: get('GITHUB_CLIENT_ID', ''),
clientSecret: get('GITHUB_CLIENT_SECRET', ''),
},
trustedProxies: getTrustProxies('TRUSTED_PROXIES'),
}
config.baseUrl = get('BASE_URL', `http://${config.host}:${config.port}`)