opnform/resources/js/middleware/custom-domains.js

21 lines
591 B
JavaScript
Raw Normal View History

export default async (to, from, next) => {
2023-11-30 10:31:56 +00:00
if (!window.config.custom_domains_enabled) {
next()
}
const isCustomDomain = getDomain(window.location.href) !== getDomain(window.config.app_url)
if (isCustomDomain && !['forms.show_public'].includes(to.name)) {
// If route isn't a public form, redirect
2023-11-30 10:31:56 +00:00
window.location.href = 'https://opnform.com/?utm_source=failed_custom_domain_redirect'
} else {
next()
}
}
function getDomain (url) {
return (new URL(url)).hostname
}
2024-01-12 14:43:28 +00:00
function isCustomDomain (url) {
return getDomain(url) !== getDomain(window.config.app_url)
}