Skip to content

Replace optimist with nconf and look for .httpserverrc settings file #131

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

Closed
wants to merge 3 commits into from

Conversation

timothykang
Copy link

I thought JSHint's method of searching up the directory tree would work nicely, as it would allow projects to share settings while also allowing overrides.

Related to #67, closes #24.

@indexzero
Copy link
Member

Cool idea! Let me review this weekend.

@indexzero indexzero added the major version Major, potentially breaking, change label Mar 19, 2015
bin/http-server Outdated
.argv;
fs = require('fs'),
path = require('path'),
nconf = require('nconf')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some people use this as a library. We should really be doing:

var nconf = require('nconf');

var config = new nconf.Provider()
  .argv({
    d: { boolean: true, default: true },
    i: { boolean: true, default: true },
    cors: { boolean: true }
  });

@indexzero
Copy link
Member

+1 if you can rebase of master

@indexzero indexzero added minor version non-breaking, non-trivial change and removed major version Major, potentially breaking, change labels Sep 22, 2015
@timothykang
Copy link
Author

Rebased and addressed comments. In the process I undid a small change I made to how the boolean showDir and autoIndex options were being parsed that would've broken backward compatibility.

@indexzero
Copy link
Member

Will take a look at this over the weekend or next week.

@kilianc

This comment has been minimized.

@BigBlueHat
Copy link
Member

This is an oldie, but a goodie. I'd like to revisit this again soon, so we can get off the abandoned optimist packaged and on to something more current--nconf seems fine by me.

@BigBlueHat BigBlueHat added major version Major, potentially breaking, change and removed minor version non-breaking, non-trivial change labels Aug 9, 2018
@timothykang timothykang force-pushed the nconf-httpserverrc branch 2 times, most recently from 27a8b27 to 7169b7f Compare August 14, 2018 20:46
@timothykang
Copy link
Author

An oldie indeed. Rebased onto current master, in light of the renewed interest.

@thornjad
Copy link
Member

@timothykang I worked on replacing optimist with minimist in #464, which I still believe is a step in the right direction, but I have to say I like this nconf approach better!

Would you mind taking a look at the merge confict in bin/http-server? Could you also look into specifying the current version of nconf, and make sure it doesn't break anything?

Thank you!

@thornjad thornjad added this to the v0.12.0 milestone Feb 28, 2019
@timothykang
Copy link
Author

@thornjad Done!

@thornjad thornjad self-requested a review April 16, 2019 14:18
Copy link
Member

@thornjad thornjad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timothykang I'm sorry to ask once again, but my v0.12 merge train has created some more merge conflicts, and has also added some non-nconf settings which need to be converted. Could you take a look?

This PR is next in my merge train queue so master will stop being moving target, I promise!

Also, go ahead and add yourself to the contributor list in package.json, this is definitely a great contribution! (you don't have to if you don't want to).

bin/http-server Outdated

var ifaces = os.networkInterfaces();
var config = new nconf.Provider().argv({ cors: { boolean: true } }),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use aliases here so that we can avoid the pattern of, for example, config.get('p') || config.get('port')? Instead, it would be nice to have

.argv({
  port: {
    alias: 'p'
  }, ...

And then just use config.get('port').

Note that I think we should use the long form config values as the keys and the short versions as aliases (#464 (comment))

bin/http-server Outdated

var port = config.get('p') || config.get('port') || parseInt(process.env.PORT, 10),
host = config.get('a') || '0.0.0.0',
ssl = !!config.get('S') || !!config.get('ssl'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use parseValues: true in .argv above rather than need to coerce here. Correct me if I'm wrong on that, I haven't used nconf before.

@timothykang
Copy link
Author

@thornjad Rebased. I added value parsing for numbers and where it made sense, but I left the keys as the short forms since not every option had a long form (they could be easily added in a follow-on PR).

@thornjad thornjad modified the milestones: v0.12.0, v0.13.0 Nov 19, 2019
@thornjad thornjad self-requested a review December 11, 2019 18:16
@karlhorky
Copy link

I guess this can probably be closed, now that #622 was merged instead (switch optimist to minimist)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major version Major, potentially breaking, change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use nconf for configuration management
6 participants