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 call method 'defaults' of undefined #844

Closed
wolneykien opened this Issue Sep 10, 2013 · 7 comments

Comments

6 participants
@wolneykien

wolneykien commented Sep 10, 2013

node_modules/sails/lib/configuration/validate.js:231
                    config = _.recursive.defaults(config.express.serverOptions,config.ssl);
                                         ^
TypeError: Cannot call method 'defaults' of undefined

Is there really something defined for the recursive key in lodash ?

@particlebanana

This comment has been minimized.

Show comment
Hide comment
@particlebanana

particlebanana Sep 10, 2013

Contributor

Nope. Looks like this is left over from the old underscore days. I found this gist where @mikermcneil is extending underscore to make it recursive: https://gist.github.com/mikermcneil/3862932

With lodash it should just be _.merge(config.express.serverOptions, config.ssl); I think, without knowing what's in those objects though I'd have to test it a bit. Want to try that out and submit a pull request?

http://lodash.com/docs#merge

Contributor

particlebanana commented Sep 10, 2013

Nope. Looks like this is left over from the old underscore days. I found this gist where @mikermcneil is extending underscore to make it recursive: https://gist.github.com/mikermcneil/3862932

With lodash it should just be _.merge(config.express.serverOptions, config.ssl); I think, without knowing what's in those objects though I'd have to test it a bit. Want to try that out and submit a pull request?

http://lodash.com/docs#merge

@wolneykien

This comment has been minimized.

Show comment
Hide comment
@wolneykien

wolneykien Sep 10, 2013

Actually, it looks like that there are more problems in the course of SSL configuration. For instance, the code cited above erases the whole config replacing it with just the result of merging config.express.serverOptions.
Moreover, the warning around there is always fired due to express.serverOptions extending in configuration/build.js (line 62). And last, but not least: that action fails due to undefined express (#843).

Yes, I will request for a pull when I'd managed it to work. :)

wolneykien commented Sep 10, 2013

Actually, it looks like that there are more problems in the course of SSL configuration. For instance, the code cited above erases the whole config replacing it with just the result of merging config.express.serverOptions.
Moreover, the warning around there is always fired due to express.serverOptions extending in configuration/build.js (line 62). And last, but not least: that action fails due to undefined express (#843).

Yes, I will request for a pull when I'd managed it to work. :)

wolneykien pushed a commit to wolneykien/sails that referenced this issue Sep 10, 2013

Paul Wolneykien
Fix/improve the SSL configuration
- Do not extend config.express.serverOptions with config.ssl before
  the config validation is done: the former is undefined by default
  (#843) and that's OK as it would fire a validation warning otherwise.

- Use _.merge instead of the undefined _.recursive.defaults to set the
  default values of config.express.serverOptions (#844). Use _.extend
  if the serverOptions wasn't defined by the user's config.
@wolneykien

This comment has been minimized.

Show comment
Hide comment
@wolneykien

wolneykien Sep 10, 2013

The configuration itself seems to work, but now I get the following error:

$ sails lift

crypto.js:100
      c.context.setKey(options.key);
                ^
Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
    at Object.exports.createCredentials (crypto.js:100:17)
    at Server (tls.js:1111:28)
    at new Server (https.js:35:14)
    at exports.createServer (https.js:54:10)
    at Array.loadExpress [as 1] (/home/manowar/repopus/node_modules/sails/lib/express/index.js:44:27)
    at listener (/home/manowar/repopus/node_modules/sails/node_modules/async/lib/async.js:462:46)
    at /home/manowar/repopus/node_modules/sails/node_modules/async/lib/async.js:416:17
    at Array.forEach (native)
    at _each (/home/manowar/repopus/node_modules/sails/node_modules/async/lib/async.js:32:24)
    at Object.taskComplete (/home/manowar/repopus/node_modules/sails/node_modules/async/lib/async.js:415:13)
    at processImmediate [as _immediateCallback] (timers.js:330:15)

wolneykien commented Sep 10, 2013

The configuration itself seems to work, but now I get the following error:

$ sails lift

crypto.js:100
      c.context.setKey(options.key);
                ^
Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
    at Object.exports.createCredentials (crypto.js:100:17)
    at Server (tls.js:1111:28)
    at new Server (https.js:35:14)
    at exports.createServer (https.js:54:10)
    at Array.loadExpress [as 1] (/home/manowar/repopus/node_modules/sails/lib/express/index.js:44:27)
    at listener (/home/manowar/repopus/node_modules/sails/node_modules/async/lib/async.js:462:46)
    at /home/manowar/repopus/node_modules/sails/node_modules/async/lib/async.js:416:17
    at Array.forEach (native)
    at _each (/home/manowar/repopus/node_modules/sails/node_modules/async/lib/async.js:32:24)
    at Object.taskComplete (/home/manowar/repopus/node_modules/sails/node_modules/async/lib/async.js:415:13)
    at processImmediate [as _immediateCallback] (timers.js:330:15)
@wolneykien

This comment has been minimized.

Show comment
Hide comment
@wolneykien

wolneykien Sep 10, 2013

Everything is OK: it was due to filenames used where certificate data is expected. ;)

wolneykien commented Sep 10, 2013

Everything is OK: it was due to filenames used where certificate data is expected. ;)

@krzysztofantczak

This comment has been minimized.

Show comment
Hide comment
@krzysztofantczak

krzysztofantczak Sep 18, 2013

and where it is expected?

krzysztofantczak commented Sep 18, 2013

and where it is expected?

@mikermcneil

This comment has been minimized.

Show comment
Hide comment
@mikermcneil

mikermcneil Sep 18, 2013

Member

@krzysztofantczak Usually, we'll make a folder called ssl in the app root and throw the certs in there:

ssl/
    gd_bundle.crt
    yourApp.crt
    yourApp.csr
    yourApp.key

In production, you can keep these certs wherever makes sense and load them however you like

Then, after @wolneykien's PR (so in the development branch on github currently) in your config, you need to read the certs, e.g.

// In config/local.js
module.exports.ssl = {
  ca: fs.readFileSync(__dirname + '../ssl/gd_bundle.crt'),                                   
  key: fs.readFileSync(__dirname + '../ssl/yourApp.key'),                                               
  cert: fs.readFileSync(__dirname + '../ssl/yourApp.crt')
};

@wolneykien I'll patch this into npm to make this easier to do once we're sure it's good (e.g. questions here and here )

@wolneykien Would you mind doing a PR to the docs with some docs on using sails.config.ssl?

Member

mikermcneil commented Sep 18, 2013

@krzysztofantczak Usually, we'll make a folder called ssl in the app root and throw the certs in there:

ssl/
    gd_bundle.crt
    yourApp.crt
    yourApp.csr
    yourApp.key

In production, you can keep these certs wherever makes sense and load them however you like

Then, after @wolneykien's PR (so in the development branch on github currently) in your config, you need to read the certs, e.g.

// In config/local.js
module.exports.ssl = {
  ca: fs.readFileSync(__dirname + '../ssl/gd_bundle.crt'),                                   
  key: fs.readFileSync(__dirname + '../ssl/yourApp.key'),                                               
  cert: fs.readFileSync(__dirname + '../ssl/yourApp.crt')
};

@wolneykien I'll patch this into npm to make this easier to do once we're sure it's good (e.g. questions here and here )

@wolneykien Would you mind doing a PR to the docs with some docs on using sails.config.ssl?

@sgress454 sgress454 closed this Dec 16, 2013

@khmereshop

This comment has been minimized.

Show comment
Hide comment
@khmereshop

khmereshop May 6, 2015

I got the same error when I try to use https ssl certification. I use keytool to generate the certificate. The keytool is a java command use to generate certification. How do I start up sails lift and pass in the password. If I do, sails lift. I got error below.

crypto.js:100
c.context.setKey(options.key);
^
Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
at Object.exports.createCredentials (crypto.js💯17)
at Server (tls.js:1130:28)
at new Server (https.js:35:14)
at exports.createServer (https.js:54:10)
at loadExpress (/opt/careApp/node_modules/sails/lib/hooks/http/initialize.js:52:39)
at /opt/careApp/node_modules/sails/lib/hooks/http/index.js:191:18
at /opt/careApp/node_modules/sails/lib/app/private/after.js:91:14
at /opt/careApp/node_modules/async/lib/async.js:254:17
at done (/opt/careApp/node_modules/async/lib/async.js:135:19)
at /opt/careApp/node_modules/async/lib/async.js:32:16
at /opt/careApp/node_modules/async/lib/async.js:251:21
at /opt/careApp/node_modules/async/lib/async.js:575:34
at handlerFn (/opt/careApp/node_modules/sails/lib/app/private/after.js:78:13)
at /opt/careApp/node_modules/async/lib/async.js:570:21
at /opt/careApp/node_modules/async/lib/async.js:249:17
at /opt/careApp/node_modules/async/lib/async.js:125:13

khmereshop commented May 6, 2015

I got the same error when I try to use https ssl certification. I use keytool to generate the certificate. The keytool is a java command use to generate certification. How do I start up sails lift and pass in the password. If I do, sails lift. I got error below.

crypto.js:100
c.context.setKey(options.key);
^
Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
at Object.exports.createCredentials (crypto.js💯17)
at Server (tls.js:1130:28)
at new Server (https.js:35:14)
at exports.createServer (https.js:54:10)
at loadExpress (/opt/careApp/node_modules/sails/lib/hooks/http/initialize.js:52:39)
at /opt/careApp/node_modules/sails/lib/hooks/http/index.js:191:18
at /opt/careApp/node_modules/sails/lib/app/private/after.js:91:14
at /opt/careApp/node_modules/async/lib/async.js:254:17
at done (/opt/careApp/node_modules/async/lib/async.js:135:19)
at /opt/careApp/node_modules/async/lib/async.js:32:16
at /opt/careApp/node_modules/async/lib/async.js:251:21
at /opt/careApp/node_modules/async/lib/async.js:575:34
at handlerFn (/opt/careApp/node_modules/sails/lib/app/private/after.js:78:13)
at /opt/careApp/node_modules/async/lib/async.js:570:21
at /opt/careApp/node_modules/async/lib/async.js:249:17
at /opt/careApp/node_modules/async/lib/async.js:125:13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment