Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create property 'path' on string 'localhost' when specifying host and port on cache property #167

Closed
geuis opened this issue Jul 18, 2016 · 4 comments

Comments

@geuis
Copy link

geuis commented Jul 18, 2016

Originally from outmoded/hapijs.com#407

I encounter a stacktrace when host and port aren't used on an options property.

In the Client subsection of http://hapijs.com/tutorials/caching, this configuration code example is given:

'use strict';

const Hapi = require('hapi');

const server = new Hapi.Server({
    cache: [
        {
            name: 'mongoCache',
            engine: require('catbox-mongodb'),
            host: '127.0.0.1',
            partition: 'cache'
        },
        {
            name: 'redisCache',
            engine: require('catbox-redis'),
            host: '127.0.0.1',
            partition: 'cache'
        }
    ]
});

server.connection({
    port: 8000
});

I am only able to get this to work with an options property:

const server = new Hapi.Server({
  debug: {
    request: ['error']
  },
  cache: {
    name: 'redisCache',
    engine: CatBox,
    options: {
      host: process.env.redisHost,
      port: process.env.redisPort
    }
  }
});

This is the stacktrace I get when I try using host and port directly on cache: {}

server-1 TypeError: Cannot create property 'path' on string 'localhost'
server-1     at createClient (/usr/local/apps/projecto/node_modules/redis/lib/createClient.js:62:26)
server-1     at Object.exports.createClient (/usr/local/apps/projecto/node_modules/redis/index.js:1081:41)
server-1     at internals.Connection.start (/usr/local/apps/projecto/node_modules/catbox-redis/lib/index.js:46:24)
server-1     at internals.Client.start (/usr/local/apps/projecto/node_modules/hapi/node_modules/catbox/lib/client.js:41:21)
server-1     at each (/usr/local/apps/projecto/node_modules/hapi/lib/server.js:247:36)
server-1     at Object.exports.parallel (/usr/local/apps/projecto/node_modules/hapi/node_modules/items/lib/index.js:70:13)
server-1     at internals.Server.initialize (/usr/local/apps/projecto/node_modules/hapi/lib/server.js:251:11)
server-1     at internals.Server.start (/usr/local/apps/projecto/node_modules/hapi/lib/server.js:182:10)
server-1     at Object.<anonymous> (/usr/local/apps/projecto/dist/webpack:/app/app.js:119:8)
server-1     at __webpack_require__ (/usr/local/apps/projecto/dist/webpack:/webpack/bootstrap c4781f2bce8764d4cada:19:1)

This is my app.js setup:

const server = new Hapi.Server({
  debug: {
    request: ['error']
  },
  cache: {
    name: 'redisCache',
    engine: CatBox,
// host and port must be commented out to avoid the error
    host: process.env.redisHost,
    port: process.env.redisPort
// No errors when "options" is uncommented
//    options: {
//      host: process.env.redisHost,
//      port: process.env.redisPort
//    }
  }
});

server.connection({
  host: process.env.serverHost,
  port: process.env.serverPort
});

// redis cache
server.app.cache = server.cache({
  cache: 'redisCache',
  segment: 'seg',
  expiresIn: 604800000 // 1 week
});

And my package.json dependencies

package.json

"dependencies": {
    "babel-plugin-transform-runtime": "^6.9.0",
    "babel-polyfill": "^6.9.0",
    "babel-runtime": "^6.9.0",
    "bcrypt": "^0.8.7",
    "catbox-redis": "^2.0.2",
    "dotenv": "^2.0.0",
    "hapi": "^13.4.1",
    "hapi-auth-cookie": "^6.1.1",
    "joi": "^8.4.2",
    "mysql": "^2.11.1",
    "node-uuid": "^1.4.7",
    "nunjucks": "^2.4.2",
    "source-map-support": "^0.4.0",
    "vision": "^4.1.0"
  }

One thought is that the babel es6 transpiling is doing something that catbox doesn't like.

@cnadeau
Copy link

cnadeau commented Feb 3, 2017

I ran into the same issue using redis.createClient and it was because the args are: createClient(port, host)

https://github.com/NodeRedis/node_redis/blob/master/lib/createClient.js#L6

inverting them caused this error

@hueniverse
Copy link
Contributor

Is this a catbox-redis bug then?

@kanongil
Copy link
Contributor

This is a catbox-redis issue. From the looks of it this can happen if you pass an empty or non-digit string as the port.

@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants