1
0
Fork 0
mirror of https://github.com/seejohnrun/haste-server.git synced 2024-11-22 20:51:21 +00:00
haste-server/docker-entrypoint.js

109 lines
2.7 KiB
JavaScript
Raw Normal View History

const {
HOST,
PORT,
KEY_LENGTH,
MAX_LENGTH,
STATIC_MAX_AGE,
RECOMPRESS_STATIC_ASSETS,
STORAGE_TYPE,
STORAGE_HOST,
STORAGE_PORT,
STORAGE_EXPIRE_SECONDS,
STORAGE_DB,
STORAGE_AWS_BUCKET,
STORAGE_AWS_REGION,
2020-08-22 20:25:10 +00:00
STORAGE_PASSWORD,
STORAGE_USERNAME,
2020-08-22 19:47:48 +00:00
STORAGE_FILEPATH,
LOGGING_LEVEL,
LOGGING_TYPE,
LOGGING_COLORIZE,
KEYGENERATOR_TYPE,
KEY_GENERATOR_KEYSPACE,
RATE_LIMITS_NORMAL_TOTAL_REQUESTS,
2020-08-22 20:12:54 +00:00
RATE_LIMITS_NORMAL_EVERY_MILLISECONDS,
RATE_LIMITS_WHITELIST_TOTAL_REQUESTS,
2020-08-22 20:12:54 +00:00
RATE_LIMITS_WHITELIST_EVERY_MILLISECONDS,
RATE_LIMITS_WHITELIST,
RATE_LIMITS_BLACKLIST_TOTAL_REQUESTS,
2020-08-22 20:12:54 +00:00
RATE_LIMITS_BLACKLIST_EVERY_MILLISECONDS,
RATE_LIMITS_BLACKLIST,
2022-06-08 09:26:32 +00:00
DOCUMENTS
} = process.env
const config = {
host: HOST,
port: Number(PORT),
keyLength: Number(KEY_LENGTH),
maxLength: Number(MAX_LENGTH),
staticMaxAge: Number(STATIC_MAX_AGE),
recompressStaticAssets: RECOMPRESS_STATIC_ASSETS,
logging: [
{
level: LOGGING_LEVEL,
type: LOGGING_TYPE,
2022-06-08 09:26:32 +00:00
colorize: LOGGING_COLORIZE
}
],
keyGenerator: {
type: KEYGENERATOR_TYPE,
2022-06-08 09:26:32 +00:00
keyspace: KEY_GENERATOR_KEYSPACE
},
rateLimits: {
2022-06-08 09:26:32 +00:00
whitelist: RATE_LIMITS_WHITELIST ? RATE_LIMITS_WHITELIST.split(',') : [],
blacklist: RATE_LIMITS_BLACKLIST ? RATE_LIMITS_BLACKLIST.split(',') : [],
categories: {
normal: {
totalRequests: RATE_LIMITS_NORMAL_TOTAL_REQUESTS,
2022-06-08 09:26:32 +00:00
every: RATE_LIMITS_NORMAL_EVERY_MILLISECONDS
},
whitelist:
2020-08-22 20:12:54 +00:00
RATE_LIMITS_WHITELIST_EVERY_MILLISECONDS ||
RATE_LIMITS_WHITELIST_TOTAL_REQUESTS
? {
totalRequests: RATE_LIMITS_WHITELIST_TOTAL_REQUESTS,
2022-06-08 09:26:32 +00:00
every: RATE_LIMITS_WHITELIST_EVERY_MILLISECONDS
}
: null,
blacklist:
2020-08-22 20:12:54 +00:00
RATE_LIMITS_BLACKLIST_EVERY_MILLISECONDS ||
RATE_LIMITS_BLACKLIST_TOTAL_REQUESTS
? {
totalRequests: RATE_LIMITS_WHITELIST_TOTAL_REQUESTS,
2022-06-08 09:26:32 +00:00
every: RATE_LIMITS_BLACKLIST_EVERY_MILLISECONDS
}
2022-06-08 09:26:32 +00:00
: null
}
},
storage: {
type: STORAGE_TYPE,
host: STORAGE_HOST,
port: Number(STORAGE_PORT),
expire: Number(STORAGE_EXPIRE_SECONDS),
bucket: STORAGE_AWS_BUCKET,
region: STORAGE_AWS_REGION,
connectionUrl: `postgres://${STORAGE_USERNAME}:${STORAGE_PASSWORD}@${STORAGE_HOST}:${STORAGE_PORT}/${STORAGE_DB}`,
db: STORAGE_DB,
user: STORAGE_USERNAME,
password: STORAGE_PASSWORD,
2022-06-08 09:26:32 +00:00
path: STORAGE_FILEPATH
},
documents: DOCUMENTS
2022-06-08 09:26:32 +00:00
? DOCUMENTS.split(',').reduce((acc, item) => {
const keyAndValueArray = item.replace(/\s/g, '').split('=')
return { ...acc, [keyAndValueArray[0]]: keyAndValueArray[1] }
}, {})
2022-06-08 09:26:32 +00:00
: null
}
2022-06-08 09:26:32 +00:00
console.log(JSON.stringify(config))