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:
Lin, Hung-Shin authored and GitHub committed 2023-11-03 21:32:12 +08:00
1 parent f93b4d757b
commit 4c2f3f5397
8 files changed
+42 -5

No files matched your search

+16
View File
@@ -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
+10
View File
@@ -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}`)