feat: enhance URL validation for webhook form to support localhost on local environment (#54)

This commit is contained in:
Gabriel Jablonski 2025-05-25 17:25:15 -03:00 committed by GitHub
parent 37c5d31718
commit 59675caf68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,6 +1,6 @@
<script>
import { useVuelidate } from '@vuelidate/core';
import { required, url, minLength } from '@vuelidate/validators';
import { required, url, minLength, or } from '@vuelidate/validators';
import wootConstants from 'dashboard/constants/globals';
import { getI18nKey } from 'dashboard/routes/dashboard/settings/helper/settingsHelper';
import NextButton from 'dashboard/components-next/button/Button.vue';
@ -22,6 +22,18 @@ const SUPPORTED_WEBHOOK_EVENTS = [
'conversation_typing_off',
];
const localhostUrl = value => {
if (!value) {
return true;
}
const isRunningOnLocalhost = ['localhost', '127.0.0.1'].includes(
window.location.hostname
);
const localUrlPattern =
/^(?:https?:\/\/)?(?:localhost|127\.0\.0\.1)(?::\d+)?(?:\/.*)?$/i;
return isRunningOnLocalhost && localUrlPattern.test(value);
};
export default {
components: {
NextButton,
@ -56,7 +68,7 @@ export default {
url: {
required,
minLength: minLength(7),
url,
url: or(localhostUrl, url),
},
subscriptions: {
required,