-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
223 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
const config = require('config') | ||
const configure = (HTTP_PROXY, HTTPS_PROXY, NO_PROXY) => { | ||
if (HTTP_PROXY) { | ||
const ga = require('global-agent') | ||
ga.bootstrap() | ||
global.GLOBAL_AGENT.HTTP_PROXY = HTTP_PROXY | ||
global.GLOBAL_AGENT.HTTPS_PROXY = HTTPS_PROXY | ||
global.GLOBAL_AGENT.NO_PROXY = NO_PROXY | ||
} | ||
} | ||
|
||
if (config.has('HTTP_PROXY')) { | ||
const ga = require('global-agent') | ||
ga.bootstrap() | ||
global.GLOBAL_AGENT.HTTP_PROXY = config.get('HTTP_PROXY') | ||
global.GLOBAL_AGENT.HTTPS_PROXY = config.get('HTTPS_PROXY') | ||
global.GLOBAL_AGENT.NO_PROXY = config.get('NO_PROXY') | ||
module.exports = { | ||
configure | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
const rateLimit = require('express-rate-limit') | ||
const config = require('config') | ||
const logger = require('./logging') | ||
let checkWindowMs = 0 | ||
let checkMax = 0 | ||
|
||
const windowMs = config.get('rateLimitWindowMs') | ||
const max = config.get('rateLimitMaxRequestAllow') | ||
|
||
const rateLimiter = rateLimit({ | ||
windowMs, | ||
max, | ||
message: `You have exceeded the ${max} requests in ${windowMs} milliseconds limit!`, | ||
headers: true | ||
}) | ||
const configure = (app, windowMs = 86400000, max = 1000) => { | ||
if (windowMs === checkWindowMs && max === checkMax) { | ||
logger.log2('debug', 'Skip ratelimit config, already config with same values') | ||
return | ||
} | ||
checkWindowMs = windowMs | ||
checkMax = max | ||
logger.log2('info', `configure rate-limiter windowMs=${windowMs} maxRequestAllow=${max}`) | ||
app.rateLimiter = rateLimit({ | ||
windowMs, | ||
max, | ||
message: `You have exceeded the ${max} requests in ${windowMs} milliseconds limit!`, | ||
headers: true | ||
}) | ||
} | ||
|
||
module.exports = { | ||
rateLimiter | ||
configure | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,36 @@ | ||
const expressSession = require('express-session') | ||
const MemoryStore = require('memorystore')(expressSession) | ||
const config = require('config') | ||
const { randomSecret } = require('../utils/misc') | ||
const logger = require('./logging') | ||
|
||
const expressSessionConfig = { | ||
cookie: { | ||
maxAge: 86400000, | ||
sameSite: config.get('cookieSameSite'), | ||
secure: config.get('cookieSecure') | ||
}, | ||
store: new MemoryStore({ | ||
checkPeriod: 86400000 // prune expired entries every 24h | ||
}), | ||
secret: randomSecret(), | ||
resave: false, | ||
saveUninitialized: false | ||
} | ||
let checkCookieSameSite = '' | ||
let checkCookieSecure | ||
|
||
const configure = (app, cookieSameSite = 'none', cookieSecure = true) => { | ||
if (cookieSameSite === checkCookieSameSite && cookieSecure === checkCookieSecure) { | ||
logger.log2('debug', 'Skip session config, already config with same values') | ||
return | ||
} | ||
|
||
const session = expressSession(expressSessionConfig) | ||
checkCookieSameSite = cookieSameSite | ||
checkCookieSecure = cookieSecure | ||
logger.log2('info', `configure express session sameSite=${cookieSameSite} secure=${cookieSecure}`) | ||
const expressSessionConfig = { | ||
cookie: { | ||
maxAge: 86400000, | ||
sameSite: cookieSameSite, | ||
secure: cookieSecure | ||
}, | ||
store: new MemoryStore({ | ||
checkPeriod: 86400000 // prune expired entries every 24h | ||
}), | ||
secret: randomSecret(), | ||
resave: false, | ||
saveUninitialized: false | ||
} | ||
app.session = expressSession(expressSessionConfig) | ||
} | ||
|
||
module.exports = { | ||
session | ||
configure | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.