hapijs

hapi single page application using inert plugin doesn't serve up api route

巧了我就是萌 提交于 2019-12-12 03:53:57
问题 I am trying to build a single page application using hapi and inert. my example code is here: https://github.com/7seven7lst/hapi-inert-test and the base of the project is built from the answer here nodejs hapi single page Basically I would like to both server static file and api json data to front end. I know how to do this in express, but haven't figure out how with hapi. the delimma is : if I use hapi only, it doesn't serve up static file, and if i use hapi+inert, it wont' serve up api

TypeError: server.views is not a function in hapi.js

谁都会走 提交于 2019-12-12 03:37:14
问题 I am a beginner on node.js I am using hapi framework for my web app. In that i am using handlebars for template. When i configure the server views i am getting the type error. 'use strict'; const hapi = require('hapi'); const server = new hapi.Server(); const inert = new require('inert'); server.connection({ host: '127.0.0.1', port: 8080, }); //Starting server server.start((error) => { if(error){ throw error; } console.log("Server running" + server); }); server.register(inert, () => { console

Migrating HTTPS server from Express to Hapi

时光总嘲笑我的痴心妄想 提交于 2019-12-12 02:23:21
问题 I'm trying to migrate an HTTPS server from Express to Hapi. The server is running fine on Express, but when I try to run it in Hapi I get messages saying "Invalid server options" and "TLS is not allowed". This is my (simplified) code with Express: var fs = require('fs'); var https = require('https'); var app = require('express')(); var options = { key: fs.readFileSync('server.key'), cert: fs.readFileSync('server.crt') }; app.get('/', function (req, res) { res.send('Hello World!'); }); https

Catbox-redis is showing disconnected error on my hapijs application

社会主义新天地 提交于 2019-12-12 01:26:42
问题 I have used to catbox-redis plugin but when i run the code i got disconnected error. When i search where i get this error, i found that it was coming from the catbox lib client.js isReady function If any about this please help me { method : 'POST', path : "/signup", config : { tags : ['api'], description : 'Customer signup', validate : { failAction: Relish.failAction, options : { abortEarly: false, }, payload : signupSchema, } }, handler: function(request, response){ let responseData = {

NodeWebkit - deploy the application

空扰寡人 提交于 2019-12-12 00:42:00
问题 I have one code base for both Web and NodeWebkit (NW) application. I use the following stack: - React - Hapi - Sequelize - Windows environment Web version of the application uses MySQL, while NW uses Sqlite. It all works fine. I have config file that compiles application for what I need (web or NW). The problem that I face now is how to deploy the NW application. Idea is to provide NW applicaiton to a client, where he will open it clicking the icon. Since I use the Node for the NW version,

Add prefix to all api's in hapi

心已入冬 提交于 2019-12-11 19:02:14
问题 I have this code written in index.js file. My api's are running successfully on the / path. Now I need add a prefix to all my api's. I don't want to add one by one by editing each file. I need to do in one go. composer((err, server) => { if (err) throw err server.initialize((errInit) => { if (err) throw errInit server.register({ register: require('hapi-cron'), routes: { prefix: '/api' }, options: { jobs: [] } }, (err) => { server.start(() => { const env = process.env.NODE_ENV const msg = `$

Getting double quotes when returning html

我怕爱的太早我们不能终老 提交于 2019-12-11 15:54:23
问题 I have below route to return privacy policy for my app. const html = `<html><body><div>dsfdsfsfdsfsfsdfdsf</div></body></html>` const handler = (request, reply) => { try { return reply(html) } catch (err) { return reply({ success: false, message: err.message, data: [] }) } } const routeConfig = { method: 'GET', path: '/privacy-policy', config: { description: 'Creates a task.', notes: ['On success, returns { "data": [ { "tasks" } ]}'], handler } } However when I am returning the html content I

Joi validation set default as empty object

南楼画角 提交于 2019-12-11 09:07:04
问题 I'm running into an issue (or what I believe to be one) with Joi validation. I'm trying to assign a value to a non-existent key if it's been passed as part of the request body. So for example: parameters: Joi.object().keys({ keyA: Joi.string().allow('').allow(null).default(null), keyB: Joi.object().keys({ b1: Joi.string(), b2: Joi.string(), b3: Joi.object().keys({ b3_1: Joi.string(), b3_2: Joi.string(), b3_3: Joi.string() }) }).default({}), keyC: Joi.object().keys({ c1: Joi.number(), c2: Joi

How to run multiple server labels on same port using node and hapi?

只愿长相守 提交于 2019-12-11 03:54:33
问题 I am trying to host api and web servers on the same node code stack. I have used labels in order to apply configurations independently to each server but only one server works. Below is the code: var hapi = require('hapi'); // server definition var server = new hapi.Server(); var runningPort = process.env.PORT || 3000; // setting up connection server.connection({ host: '0.0.0.0', port: runningPort, labels: ['api'] }); server.connection({ host: '0.0.0.0', port: runningPort, labels: ['web'] });

Hapi.js Proxy - change the response before reply

天大地大妈咪最大 提交于 2019-12-10 22:42:31
问题 I'm trying to test Hapi.js for a new project I'm working on My goal is to trigger a request on my Hapi server and this request will trigger another request on a remote server using Hapi proxy, and the response will be only specific properties from the remote response To test this a request to /api/type3/name must be made which will invoke an API call to GitHub's API to get the user object Code: server.route({ method: 'GET', path: '/api/type3/{name}', handler: { proxy: { mapUri: function