Comments (2)
@c-hartmann If you want to validate that the protocol is "mongodb://", you can use joi's uri()
validator:
var Joi = require('joi');
function isMongoUrl(url) {
var mongodbSchema = Joi.string().uri({
scheme: ['mongodb']
});
Joi.assert(url, mongodbSchema);
}
Actually, the validator library supports custom schemes too:
function isMongoUrl(url) {
if (!validator.isURL(url, {
protocols: ['mongodb']
})) {
throw new Error('must be URL like');
}
}
from node-convict.
I totally agree with @pdehaan suggestions.
We would loose some "validation strictness" if we set {require_valid_protocol: false}
by default in convict
.
Here is a full working code:
const validator = require('validator');
convict.addFormat({
name: 'mongo-uri',
validate: function(val) {
if (!validator.isURL(val, {protocols: ['mongodb']})) {
throw new Error('must be a MongoDB URI');
}
}
});
var conf = convict({
uri: {
doc: 'Mongo URI',
format: 'mongo-uri',
default: ''
}
});
conf.load({uri: 'mongodb://localhost:27017/some_db_name'});
conf.validate({strict: true});
@c-hartmann could you please close this issue?
from node-convict.
Related Issues (20)
- Update validator to latest (major) version HOT 2
- "required" property should be a must-have HOT 3
- Convict doesn't persist date / other custom objects
- Publish [email protected] on NPM HOT 16
- 6.0.1 version of Convict-format-with-validator package is using vulnerable version of validator module HOT 1
- Could you help remove the vulnerability introduced by package yargs-parser? HOT 3
- Version 5.2.1 of convict is tagged as latest on npm HOT 2
- Support for env variable arrays HOT 1
- Error: Critical dependency: the request of a dependency is an expression when importing convict into react-app HOT 5
- how to change the environment variables in docker run command
- "Type instantiation is excessively deep and possibly infinite" when using default: null HOT 5
- Get default value of a property of an object when the object is an array item HOT 5
- Feature request: `toJson`-method HOT 1
- addParser async parse
- custom formats override set order
- Bug - Prototype Pollution on .set() HOT 20
- [Feature Request] check method to check if key exist or not
- Infer typescript types of getProperties
- Crashing on keys with dot HOT 1
- .env value doesnt override default convict config value.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-convict.