Hi! I'm not sure if it is a bug
I'm using "@hapi/hapi": "^18.3.2"
, "@hapi/joi": "^16.0.1"
,
My routes looks like:
'use strict';
const Joi = require('@hapi/joi');
module.exports = [
{
method: 'GET',
path: '/users/new',
handler: (request, h) => {
return h.view('users/new');
}
},
{
method: 'POST',
path: '/users',
handler: (request, h) => {
return h.view('users/new');
},
options: {
validate: {
payload: Joi.object().keys({
username: Joi.string()
})
}
}
}
];
I get the following error when I start the server:
Error: Invalid schema content: ($_root.alternatives)
at new module.exports (/home/sitraka/Projects/camoicenter/node_modules/@hapi/hoek/lib/error.js:21:15)
at Object.module.exports [as assert] (/home/sitraka/Projects/camoicenter/node_modules/@hapi/hoek/lib/assert.js:20:11)
at Object.exports.schema (/home/sitraka/Projects/camoicenter/node_modules/@hapi/hapi/node_modules/@hapi/joi/lib/cast.js:50:10)
at internals.Object.keys (/home/sitraka/Projects/camoicenter/node_modules/@hapi/hapi/node_modules/@hapi/joi/lib/types/object/index.js:363:35)
at Object.exports.schema (/home/sitraka/Projects/camoicenter/node_modules/@hapi/hapi/node_modules/@hapi/joi/lib/cast.js:31:29)
at internals.Object.keys (/home/sitraka/Projects/camoicenter/node_modules/@hapi/hapi/node_modules/@hapi/joi/lib/types/object/index.js:363:35)
at Object.exports.schema (/home/sitraka/Projects/camoicenter/node_modules/@hapi/hapi/node_modules/@hapi/joi/lib/cast.js:31:29)
at module.exports.internals.Any.root.compile (/home/sitraka/Projects/camoicenter/node_modules/@hapi/hapi/node_modules/@hapi/joi/lib/index.js:157:25)
at Object.exports.compile (/home/sitraka/Projects/camoicenter/node_modules/@hapi/hapi/lib/validation.js:21:49)
at forEach (/home/sitraka/Projects/camoicenter/node_modules/@hapi/hapi/lib/route.js:196:43) path: '$_root.alternatives' }
im having hard time finding good documentation on how to setup ssl
this is what I have
const server = hapi.server({
port: port,
host: configs.APIServer[env].Hostname,
routes: {
cors: {
origin: [configs.APIServer[env].Protocol +
"://" +
configs.WebServer[env].Hostname +
":" +
configs.WebServer[env].Port, configs.WebServer[env].Protocol +
"://" +
configs.WebServer[env].IP +
":" +
configs.WebServer[env].Port
]
}
}
// ,debug: {
// request: env === "production" ? ["error"] : ["error", "debug"]
// }
})
do i just need to add on the bottom:
, {
tls: ssloptions
}
where ssloptions is the certs
-I, --ignore - ignore a list of globals for the leak detection (comma separated), this is an alias of globals property in .labrc file. To ignore symbols, pass the symbol's string representation (e.g. Symbol(special)).
initServer(server: Server)
where Server
is imported from @hapi/hapi.Server
. When I pass to this function a variable named server: Hapi.Server = new Hapi.Server()
where Hapi
is imported from @types/hapi
, the compiler yields the error Property 'token' is missing in type 'import("/home/foo/bar/myproject/node_modules/@types/hapi/index").AuthCredentials' but required in type 'import("/home/foo/bar/myproject/node_modules/@types/hapi__hapi/index").AuthCredentials'
. Why are the two types different? How can I solve this problem? Thanks :)
@types/hapi
is for package the package hapi
, and the official package moved to @hapi/hapi
this year, and you need to use @types/hapi__hapi
await server.register([
{ plugin: require('./routes/surveys') },
{ plugin: require('./routes/companies') },
{
plugin: yar,
options: {
cookieOptions: {
password: 'the-password-must-be-at-least-32-characters-long',
isSecure: true
}
}
},
Vision
]);
Using it like this
static inviteUserShowForm(request, h) {
request.yar.set('success', 'Invitation send successfully.');
return h.view('invite-user');
}