feat: enhance URL validation for webhook form to support localhost on local environment (#54)
This commit is contained in:
parent
37c5d31718
commit
59675caf68
@ -1,6 +1,6 @@
|
|||||||
<script>
|
<script>
|
||||||
import { useVuelidate } from '@vuelidate/core';
|
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 wootConstants from 'dashboard/constants/globals';
|
||||||
import { getI18nKey } from 'dashboard/routes/dashboard/settings/helper/settingsHelper';
|
import { getI18nKey } from 'dashboard/routes/dashboard/settings/helper/settingsHelper';
|
||||||
import NextButton from 'dashboard/components-next/button/Button.vue';
|
import NextButton from 'dashboard/components-next/button/Button.vue';
|
||||||
@ -22,6 +22,18 @@ const SUPPORTED_WEBHOOK_EVENTS = [
|
|||||||
'conversation_typing_off',
|
'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 {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
NextButton,
|
NextButton,
|
||||||
@ -56,7 +68,7 @@ export default {
|
|||||||
url: {
|
url: {
|
||||||
required,
|
required,
|
||||||
minLength: minLength(7),
|
minLength: minLength(7),
|
||||||
url,
|
url: or(localhostUrl, url),
|
||||||
},
|
},
|
||||||
subscriptions: {
|
subscriptions: {
|
||||||
required,
|
required,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user