Hi, I have a schema:taskRelatedContent: Joi.array()
.items(relatedContent)
.allow(null),
relatedContent translates to:const relatedContent = Joi.object().keys({
contentId: Joi.string(),
lang: Joi.array(),
displayName: Joi.string(),
url: Joi.string(),
mimeType: Joi.string(),
});
For some reason, the Joi.validate fails saying:
"ValidationError: child \"taskRelatedContent\" fails because [\"taskRelatedContent\" at position 0 fails because [\"contentId\" is not allowed, \"lang\" is not allowed, \"displayName\" is not allowed, \"url\" is not allowed, \"mimeType\" is not allowed]]\n
There is obviously something mighty obvious in here, that is causing this.
Pulling my hairs to see what. Does anyone else see what I am doing wrong in here?
we used to have style.md for the style guide. Now I can only find https://github.com/hapijs/eslint-plugin-hapi
Is the style defined somewhere or is this what we have ?
Can someone help me with this query?
I have 1 route, 2 different joi schemas and I want to be able to dynamically select which schema I use based on a field in the payload.
"One route, 2 schemas (Hapi.js with Joi)"
So for context I have a hapi route and am using joi validation "someSchema" hapiRoute.js:
"validate": {
"payload": someSchema
}
In schema.js:
function ChooseSchema(schemaA, schemaB) {
return Joi.when(Joi.ref("payload.data.attributes.someField"), {
"is": Joi.string().valid("fieldIsValue"),
"then": schemaA,
"otherwise": schemaB
});
}
module.exports = {
"someSchema": ChooseSchema(schemaA, schemaB)
}
Where schemaA & schemaB are different
So I am trying to use "schemaA" if "someField" id equal to a value: "fieldIsValue", otherwise use schemaB. Currently it is not getting this value "someField", and so just returning schemaB I believe
strip
method? server.route({
method: 'GET',
path: '/foo/{id}',
handler: (req, reply) => {
server.methods.fooHandler(req.params.id)
},
config: {
response: {
status: {
200: joi.object(
_id: joi.string(),
name: joi.string(),
updatedAt: joi.strip(),
createdAt: joi.strip(),
__v: joi.strip()
)
},
}
}
})
Hello, my name is Liora and I am currently hunting open source projects for company NeuraLegion (www.neuralegion.com)
We just launched a free annual subscription for open source projects for our AIAST tool NexPloit.
If you are interested, please, reach us on opensource@neuralegion.com!
Thank you for your time and consideration! If you have any questions, please do not hesitate to contact us!
Best,
stripUnknown
flag: https://github.com/hapijs/joi/blob/master/API.md#anyvalidatevalue-options
/user/:id(\\d+)
server.route({
method: 'GET',
path: '/user/{id}',
options : {
validate : {
params : {
id : Joi.number().integer()
}
}
},
handler: function (req, handler) {
return req.params.id
}
})
has anyone run into a problem where Hapi intermittently throws CORS access errors?
we have an old backend server (Hapi 14.x) running on AWS and a frontend Angular service with a different URL. when the frontend queries the server sometimes it works just fine but then at other times it randomly errors out with CORS problems and i haven't been able to determine a pattern.
the server side has the following code on initialization
cors: {
credentials: true
}
reading the docs it seems like without explicitly setting origin
it defaults to ['*']
var Hapi=require('hapi');
var routes=require('./Routes/routes');
var admin=require('./Model/admin');
admin.createAdmin();
var port=process.env.port||3000;
var server = new Hapi.Server()
server.connection({
port:port,
host:'localhost',
routes: {
cors: true
}
})
routes.forEach((route, index)=>{
server.route(route)
})
server.register(
[
{
register:require('good'),
options:{
ops:{
interval:10000
},
reporters:{
console:[
{
module:'good-squeeze',
name:'Squeeze',
args:[{log:'*',response:'*',request:'*'}]
},
{
module:'good-console'
},
'stdout'
]
}
}
},
],
function(err){
if(err) {console.log('error',"failed to install plugins")
throw err;
}
server.log("info","plugins registered")
}
);
server.start( function(err){
if(err) throw err;
console.log('server running at '+server.info.uri );
}