webpro / dyson

Node server for dynamic, fake JSON.
837 stars 62 forks source link

Return return express server instead of express #92

Closed jasperblues closed 5 years ago

jasperblues commented 5 years ago

Given the following:


    util.options.set(options);

    var rawConfigs = loader.load(options.configDir);

    var configs = defaults.assignToAll(rawConfigs);

    var app = initExpress(options.port, options.https);

    registerServices(app, options, configs);

    return app;

};

If we returned instead:


var initExpress = function(port, secureOptions) {

    var app = express();

    if(secureOptions) {
        const server = https.createServer(secureOptions, app).listen(port);
    } else {
        const server = app.listen(port);
    }

    return server;
};```

^-- if we returned server from above, it would be possible to close programmatically, eg for specs (I created specs to prove each fake endpoint works, since they were slightly complex). 
webpro commented 5 years ago

You can use your own instance of express, and install the dyson middleware onto that, as shown the second example at https://github.com/webpro/dyson#custom-middleware. That's what you're after, right?

webpro commented 5 years ago

Closing due to inactivity.