supercharge / framework

The Supercharge core code
https://superchargejs.com
MIT License
23 stars 6 forks source link

Allow options when creating HTTP server #5

Closed marcuspoehls closed 3 years ago

marcuspoehls commented 5 years ago

A Supercharge app relies on the default HTTP (hapi) server configuration when starting an application. Allow users to customize the creation of an HTTP server with custom options. The hapi server accepts a handful of options to define the behavior.

Expected Result Merge a custom server configuration with the options provided by a user while creating the server instance in src/foundation/http/kernel.js.

Load a custom server configuration via Config.get('server') which references the options defined in the app’s config/server.js

venikman commented 4 years ago

looks like config/server.js have been moved or renamed to index.js into config folder? Also, I would like to start writing tests first. What do you think? @marcuspoehls I started to plan a schema for validation for options but then I think, why we have to do it? hapi already does validation so we just have to accept whatever user will pass as an option? Or for documentation you want to add it like you have assertions for ava ?

venikman commented 4 years ago

this is draft or even a note list of options:

{
    address: {
        default : '0.0.0.0' || this.host
    },
    app : {
        default : {}
    },
    autoListen : {
        default : true  // if port exist can noot be false, good apportunity to use a new feature of Joi
    },
    cache : {
        default: { provider: { constructor: require('catbox-memory'), options: { partition: 'hapi-cache' } } }
        // for intial implementation we can skip it, and open whole new issue to it(for me looks like a big enough issue)
    },
    compression : {
        default : { minBytes: 1024, default : 1024  } || false
    },
    debug : {
        default : { request: ['implementation'] },
        options : {
            log : [], //server events via
            request : []
        }
    },
    // already exist
    host : {
        default : 'localhost' // if OS did not change it
    }
    listener : {
        // default = none, Object
    },
    load : {
        default: {
            sampleInterval: 0 //maxHeapUsedBytes, maxHeapUsedBytes, maxEventLoopDelay
        }
    },
    mime : {
        // default = none  for it deserve
    },
    operations : {
        default : { cleanStop: true }
    },
    plugins : {
        default : {}
    },
    // already exist
    port : {
        default : 0
    },
    query : {
        default : {},
        defaultParser : {
            // parser = none or method
        }
    },
    // already exist
    routes : {
        // default = none
    },
    state : {
        default: {
            strictHeader: true,
            ignoreErrors: false,
            isSecure: true,
            isHttpOnly: true,
            isSameSite: 'Strict',
            encoding: 'none'
        }
    },
    tls : {
        // default = none
    },
    uri : {
        // Default value: constructed from runtime server information
    }
}
marcuspoehls commented 4 years ago

@venikman Your draft for the options is impressive! Looks like you've listed all available hapi server options :)

Related to the missing config/server.jsfile: this superchargejs/framework repository only provides the config utility. The actual configuration should be part of the Supercharge application boilerplate. The Supercharge app repo is located at superchargejs/supercharge.

When starting a Supercharge HTTP server, it'll read all configuration files and the HTTP server (hapi) will then use the config defined in a configuration file. This server configuration file should then be located in the application in config/server.js.

Does this make sense?