mirror of
https://github.com/imputnet/cobalt.git
synced 2024-12-29 11:06:10 +00:00
api: configurable rate limit through env
This commit is contained in:
parent
a70fc840dc
commit
391cf16c87
|
@ -22,8 +22,8 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) {
|
|||
};
|
||||
|
||||
const apiLimiter = rateLimit({
|
||||
windowMs: 60000,
|
||||
max: 20,
|
||||
windowMs: env.rateLimitWindow * 1000,
|
||||
max: env.rateLimitMax || 20,
|
||||
standardHeaders: true,
|
||||
legacyHeaders: false,
|
||||
keyGenerator: req => generateHmac(getIP(req), ipSalt),
|
||||
|
@ -36,8 +36,8 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) {
|
|||
})
|
||||
|
||||
const apiLimiterStream = rateLimit({
|
||||
windowMs: 60000,
|
||||
max: 25,
|
||||
windowMs: env.rateLimitWindow * 1000,
|
||||
max: env.rateLimitMax || 20,
|
||||
standardHeaders: true,
|
||||
legacyHeaders: false,
|
||||
keyGenerator: req => generateHmac(getIP(req), ipSalt),
|
||||
|
@ -51,7 +51,7 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) {
|
|||
|
||||
app.set('trust proxy', ['loopback', 'uniquelocal']);
|
||||
|
||||
app.use('/api/:type', cors({
|
||||
app.use('/api', cors({
|
||||
methods: ['GET', 'POST'],
|
||||
...corsConfig
|
||||
}))
|
||||
|
|
|
@ -28,18 +28,25 @@ const
|
|||
|
||||
// API mode related environment variables
|
||||
apiEnvs = {
|
||||
apiURL,
|
||||
apiPort: process.env.API_PORT || 9000,
|
||||
apiName: process.env.API_NAME || 'unknown',
|
||||
|
||||
listenAddress: process.env.API_LISTEN_ADDRESS,
|
||||
freebindCIDR: process.platform === 'linux' && process.env.FREEBIND_CIDR,
|
||||
|
||||
corsWildcard: process.env.CORS_WILDCARD !== '0',
|
||||
corsURL: process.env.CORS_URL,
|
||||
|
||||
cookiePath: process.env.COOKIE_PATH,
|
||||
tiktokDeviceInfo: process.env.TIKTOK_DEVICE_INFO && JSON.parse(process.env.TIKTOK_DEVICE_INFO),
|
||||
|
||||
rateLimitWindow: (process.env.RATELIMIT_WINDOW && parseInt(process.env.RATELIMIT_WINDOW)) || 60,
|
||||
rateLimitMax: (process.env.RATELIMIT_MAX && parseInt(process.env.RATELIMIT_MAX)) || 20,
|
||||
|
||||
processingPriority: process.platform !== 'win32'
|
||||
&& process.env.PROCESSING_PRIORITY
|
||||
&& parseInt(process.env.PROCESSING_PRIORITY),
|
||||
tiktokDeviceInfo: process.env.TIKTOK_DEVICE_INFO && JSON.parse(process.env.TIKTOK_DEVICE_INFO),
|
||||
freebindCIDR: process.platform === 'linux' && process.env.FREEBIND_CIDR,
|
||||
apiURL
|
||||
&& parseInt(process.env.PROCESSING_PRIORITY)
|
||||
}
|
||||
|
||||
export const
|
||||
|
|
Loading…
Reference in a new issue