futurepress / react-native-static-server

HTTP static file server for React Native
MIT License
360 stars 183 forks source link

Refactor StaticServer constructor #32

Closed rangav closed 6 years ago

rangav commented 6 years ago

Hi

This is a suggestion, Too many conditions check in constructor, my suggestion below

let server = new StaticServer({port: 8080, localOnly : true, keepAlive : true });

class StaticServer {
          constructor(opts) {
                       if(opts)
                        {
                this.port = `${opts.port}` || PORT;
                this.root = opts.root || ROOT;
                this.localOnly = opts.localOnly || false;
                this.keepAlive = opts.keepAlive || false;
             }
            else{
                this.port = PORT;
                this.root = ROOT;
                this.localOnly = false;
                this.keepAlive = false;
                   }
             }

....
}

let me know your feedback

fchasen commented 6 years ago

Agreed this could be simpler, but don't think it is worth breaking changes.