mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: put survey and bug report url to backend (#57)
* feat: put survey and bug report url to backend * fix: centralize hardcoded url to config * fix: validate url before redirecting
This commit is contained in:
1 parent
f93b4d757b
commit
4c2f3f5397
8 files changed
+42
-5
No files matched your search
@@ -30,4 +30,20 @@ router.use(
|
||||
commands
|
||||
)
|
||||
|
||||
router.get('/survey', (req, res) => {
|
||||
if (!config.surveyUrl) {
|
||||
res.status(404).send('Survey not configured')
|
||||
return
|
||||
}
|
||||
res.redirect(config.surveyUrl)
|
||||
})
|
||||
|
||||
router.get('/bug-report', (req, res) => {
|
||||
if (!config.bugReportUrl) {
|
||||
res.status(404).send('Bug report not configured')
|
||||
return
|
||||
}
|
||||
res.redirect(config.bugReportUrl)
|
||||
})
|
||||
|
||||
export default router
|
||||
@@ -11,6 +11,14 @@ function getTrustProxies(key) {
|
||||
.filter((p) => validator.isIPRange(p) || validator.isIP(p))
|
||||
}
|
||||
|
||||
function getUrl(key) {
|
||||
const url = get(key, '')
|
||||
if (validator.isURL(url)) {
|
||||
return validator.trim(url)
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
const config = {
|
||||
host: get('HOST', 'localhost'),
|
||||
port: get('PORT', 3000),
|
||||
@@ -30,6 +38,8 @@ const config = {
|
||||
clientSecret: get('GITHUB_CLIENT_SECRET', ''),
|
||||
},
|
||||
trustedProxies: getTrustProxies('TRUSTED_PROXIES'),
|
||||
surveyUrl: getUrl('SURVEY_URL', ''),
|
||||
bugReportUrl: getUrl('BUG_REPORT_URL', ''),
|
||||
}
|
||||
|
||||
config.baseUrl = get('BASE_URL', `http://${config.host}:${config.port}`)
|
||||
|
||||
Reference in new issue
Block a user