hapijs

I am trying to connect to connect to my SQL server database with node and hapi.js

孤街醉人 提交于 2020-05-27 12:37:45
问题 I am trying to test out connection to my sql server using node and hapi.js and run a simple query on one of my tables. I am fairly new to node and Hapi so I am just trying to figure this out so first my folder structure is as follows I have a folder called api which has routes in it and that is where I am doing my routes get_aosdata.js this works I tested it just passing back 'hello world' then I have a query folder under api this is where I am setting my db connections in connection.js this

Hapi/Joi validation with nested object

妖精的绣舞 提交于 2020-05-23 08:07:09
问题 I have the following validation on one of my routes: payload: { keywordGroups: Joi.array().items(Joi.object().keys({ language: Joi.string().required(), containsAny: Joi.array().items(Joi.string()).default([]).when('containsAll', { is: [], then: Joi.required() }), containsAll: Joi.array().items(Joi.string()).default([]).when('containsAny', { is: [], then: Joi.required() }), notContainsAll: Joi.array().items(Joi.string()).default([]), notContainsAny: Joi.array().items(Joi.string()).default([])

How to allow any other key in Joi [duplicate]

折月煮酒 提交于 2020-02-23 08:42:08
问题 This question already has an answer here : Joi object validation: How to validate values with unknown key names? (1 answer) Closed 2 years ago . I have a simple requirement. I tried to search on the internet as well as documentation but failed. So here is what I want to achieve: I have a schema: const schema = Joi.object().keys({ a: Joi.string().required(), b: Joi.string().required() }); Now, How do I configure it such that any other key in the object would be allowed? With this schema, it

apollostack/graphql-server - how to get the fields requested in a query from resolver

余生长醉 提交于 2020-01-21 07:08:07
问题 I am trying to figure out a clean way to work with queries and mongdb projections so I don't have to retrieve excessive information from the database. So assuming I have: // the query type Query { getUserByEmail(email: String!): User } And I have a User with an email and a username , to keep things simple. If I send a query and I only want to retrieve the email, I can do the following: query { getUserByEmail(email: "test@test.com") { email } } But in the resolver, my DB query still retrieves

apollostack/graphql-server - how to get the fields requested in a query from resolver

戏子无情 提交于 2020-01-21 07:07:48
问题 I am trying to figure out a clean way to work with queries and mongdb projections so I don't have to retrieve excessive information from the database. So assuming I have: // the query type Query { getUserByEmail(email: String!): User } And I have a User with an email and a username , to keep things simple. If I send a query and I only want to retrieve the email, I can do the following: query { getUserByEmail(email: "test@test.com") { email } } But in the resolver, my DB query still retrieves

Nodejs Hapi - How to enable cross origin access control

夙愿已清 提交于 2020-01-14 07:15:18
问题 I am working HapiJs Restful web service and trying to enable cors so any client even from different domain can consume my services. I tried cors=true in server connection object but didn't work. 回答1: Where did you put cors=true ? Could you add some code? Without know exactly where you've put cors = true , this bit of code may help you: server.connection({ routes: { cors: true } }) Or try adding the allowed cors in the config section of your route. server.route({ config: { cors: { origin: ['*'

await is only valid in async function - when using mongoosejs exec()

谁都会走 提交于 2020-01-14 05:52:28
问题 I am porting a Hapi project to v17 and running into some issues with Mongoose when moving to async/await. With any of my code that uses 'await', on a model (mongoose), object for example: const result = await User.findOne({email: email}).exec(); I get the following exception when running 'node server.js' await User.findOne({}).exec(); ^^^^^ SyntaxError: await is only valid in async function at new Script (vm.js:74:7) at createScript (vm.js:246:10) at Object.runInThisContext (vm.js:298:10) at

Hapi does not return data attribute from Boom error

大城市里の小女人 提交于 2020-01-03 08:39:48
问题 When replying with a Boom error from my Hapi route... { method: 'PUT', path:'foo', handler: function (request, reply) { reply(Boom.badRequest('something', { stuff: 'and more' })); } } ... I get the following response: {"statusCode":400,"error":"Bad Request","message":"something"} It's missing the data object which provides the details of the error! What's the deal? 回答1: On the Hapi documentation it references the output.payload property on the boom object, set by default to include statusCode

Joi multiple when condition

我怕爱的太早我们不能终老 提交于 2020-01-03 04:38:24
问题 I want to do a validation with Joi in my body, but it seems never work and fall all the time in the same condition. So if i POST with this endPoint: /elasticSearch?eType=scroll&scroll=1h Body:{} that supposed to throw an error, because eType is scroll and in this case scroll_id need to be required,not null, not empty. even when i POST with this endPoint: /elasticSearch?eType=search&scroll=1h Body:{} that supposed to throw an error, because eType is search and in this case query need to be

How app.listen() and app.get() work on express and hapi

那年仲夏 提交于 2020-01-02 07:14:11
问题 With http node module (only native modules) how i can recreate app.listen() and app.get() use http module with a constructor var app = function(opts) { this.token= opts.token } app.prototype.get = function(callback) { // use request and response of app.listen() } app.prototype.active = function(callback) { // use request and response of app.listen() // return on callback some manipulate //request params } app.prototype.listen = function() { // start http or https server } Import the modules