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

"path" argument must be of type string #43

Closed
blackbeario opened this issue Mar 20, 2019 · 2 comments
Closed

"path" argument must be of type string #43

blackbeario opened this issue Mar 20, 2019 · 2 comments

Comments

@blackbeario
Copy link

blackbeario commented Mar 20, 2019

I am getting an undefined TypeError for the path argument. It seems similar to this issue #10, but in my case return loopbackSSL.startServer(app); follows my boot function. See below:

boot(app, __dirname, function (err) {
    if (err) throw err;
    // Start the server if `$ node server.js`.
    if (require.main === module) {
        app.io = require('socket.io')(loopbackSSL.startServer(app));
        require('socketio-auth')(app.io, {
            authenticate: function (socket, value, callback) {
                // We can log the user's info from the socket cookie
                // console.log(socket.handshake.headers.cookie);
                socket.client.accessToken = null;
                socket.client.userId = null;
                if (value && value.userId && value.id) {
                    // Value yields access token and userID.
                    var AccessToken = app.models.AccessToken;
                    // Get credentials sent by the client.
                    var token = AccessToken.findOne({
                        where: {
                            and: [{userId: value.userId}, {id: value.id}]
                        }
                    }, function (err, tokenDetail) {
                        if (err) throw err;
                        if (tokenDetail) {
                            // Add user Id to app connections.
                            socket.client.accessToken = tokenDetail;
                            socket.client.userId = value.userId;
                            callback(null, true);
                        } else {
                            callback(null, true);
                        }
                    });
                } else {
                    // Set to false to disconnect user.
                    callback(null, true);
                }
            },
            postAuthenticate: function (socket, data) {
                console.log("user connected User:", socket.client.userId ? socket.client.userId : "anonymous");
            }
        });
        app.io.on('connection', function (socket) {
            socket.on('disconnect', function () {
                console.log('user disconnected User:', socket.client.userId ? socket.client.userId : "anonymous");
            });
        });
    }
});

return loopbackSSL.startServer(app);

Here's my config (actual server replaced with myserver):

"httpMode": false,
  "certConfig": {
    "path": "/etc/ssl/myserver.com/",
    "key": "myserver.com.pem",
    "cert": "myserver.com.pem",
    "ca": [],
    "requestCert": false,
    "rejectUnauthorized": false
  },

The error reads:

Error reading certificates TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at assertPath (path.js:39:11)
    at Object.resolve (path.js:1085:7)
    at getServerOptions (/var/www/api/node_modules/loopback-ssl/lib/loopback-ssl.js:64:23)
    at Object.startHttps (/var/www/api/node_modules/loopback-ssl/lib/loopback-ssl.js:30:15)
    at Object.startServer (/var/www/api/node_modules/loopback-ssl/index.js:14:24)
    at /var/www/api/server/server.js:48:51
    at /var/www/api/node_modules/loopback-boot/lib/executor.js:65:5
    at /var/www/api/node_modules/loopback-boot/node_modules/async/lib/async.js:251:17
    at /var/www/api/node_modules/loopback-boot/node_modules/async/lib/async.js:154:25
    at /var/www/api/node_modules/loopback-boot/node_modules/async/lib/async.js:248:21
    at /var/www/api/node_modules/loopback-boot/node_modules/async/lib/async.js:612:34
    at process._tickCallback (internal/process/next_tick.js:61:11)
    at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

I guess this could be something related to my boot function using socket.io, or an incorrect implementation of loopbackSSL.startServer(app);, which relates to #35. We need to have some examples of using this package with modified boot scripts and appStartEvents.

@blackbeario
Copy link
Author

Furthermore, if I remove my server.js file contents completely and replace with the example server.js from the README, e.g.

var loopback = require('loopback');
var boot = require('loopback-boot');
var loopbackSSL = require('loopback-ssl');
 
var app = module.exports = loopback();
 
boot(app, __dirname, function(err) {
  if (err) throw err;
});
 
return loopbackSSL.startServer(app);

I get this error:

Error reading certificates TypeError: Cannot read property 'path' of undefined
    at getServerOptions (/var/www/api/node_modules/loopback-ssl/lib/loopback-ssl.js:64:35)
    at Object.startHttps (/var/www/api/node_modules/loopback-ssl/lib/loopback-ssl.js:30:15)
    at Object.startServer (/var/www/api/node_modules/loopback-ssl/index.js:14:24)
    at Object.<anonymous> (/var/www/api/server/server.js:11:20)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

@blackbeario
Copy link
Author

This ended up being because I was using config.test.json instead of config.json because I have separate environment configs, and I didn't have the loopback-ssl config in config.json.

So, this presents another issue, how to make loopback-ssl recognize the correct config file based on env settings. Currently, it seems it will only recognize config.json and not config.test.json, config.staging.json, or config.production.json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant