2023-11-29 13:53:08 +00:00
|
|
|
export default async (to, from, next) => {
|
2023-11-30 10:31:56 +00:00
|
|
|
if (!window.config.custom_domains_enabled) {
|
2023-11-29 13:53:08 +00:00
|
|
|
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'
|
2023-11-29 13:53:08 +00:00
|
|
|
} else {
|
|
|
|
next()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getDomain (url) {
|
|
|
|
return (new URL(url)).hostname
|
|
|
|
}
|