URL Validation Error
URL Validation Error
Hi all. I am using NodeJS with Express server and DataTables.net Editor server module.
I have a form where the user is submitting a URL.
If I submit a new item with URL http://www.google.com it works. When I use a different URL such as https://gluedata.harvestapp.com/time (which is a valid url) I get the validation error. Using http://gluedata.harvestapp.com/time works. So I suspect it has something to do with https. Or am I doing something wrong?
The code:
// Editor Code
'use strict';
const
{
Editor,
Field,
Validate,
Mjoin,
Format,
Options
} = require('datatables.net-editor-server'),
db = require('../db'),
uuidv4 = require('uuid/v4'),
{logger} = require('../logger');
exports.LinksAPI = (req, res, next) => {
const editor = new Editor(db, 'links', 'links.uuid')
.fields(
new Field('links.uuid'),
new Field('links.name')
.validator(Validate.required(
new Validate.Options(
{message: 'The link name is required.'}
))),
new Field('links.description')
.validator(Validate.required(new Validate.Options(
{message: 'The link description is required.'}
))),
new Field('links.url')
.validator(Validate.required(new Validate.Options(
{message: 'The link url is required.'}
)))
.validator(Validate.dbUnique(new Validate.Options(
{message: 'There is already a link with that URL.'}
)))
.validator(Validate.url(new Validate.Options(
{message: 'You have specified an invalid URL.'}
))),
// new Field('links.icon')
// .validator(Validate.fileExtensions(
// ['jpg', 'jpeg', 'png', 'bmp'],
// 'The file must be an image file.'))
);
editor.on('preCreate', (editor, values) => {
console.log(values);
editor.field('links.uuid').setValue(uuidv4());
});
editor.process(req.body)
.then(function () {
res.json(editor.data());
})
.catch(err => {
logger.log('error', err.toString());
res.send({});
});
};
This question has an accepted answers - jump to answer
Answers
Would love any idea's on this.
Hi,
Sorry we missed this one. You are absolutely correct, it was the
httpsthat was causing the issue. The valid-url library that we use for the URL validation has an option to allow https - I've added that in now. You can make that modification locally, or it will be in the 1.9.1 release.Allan
Thanks Allan. That solved it.