src/index.js
/**
 * Create a HTTP(s) server
 * @param {string} ip The IP the server will listen to
 * @param {string} port The port the server will listen to
 * @param {CertificateObject} certificateConfiguration Possible certificate configuration
 * @returns {Promise<void>}
 */
Create a HTTP(s) server
@param {string} ip The IP the server will listen to
@param {string} port The port the server will listen to
@param {CertificateObject} certificateConfiguration Possible certificate configuration
@returns {Promise}
Create a HTTP ( s ) server @param { string } ip The IP the server will listen to @param { string } port The port the server will listen to @param { CertificateObject } certificateConfiguration Possible certificate configuration @returns { Promise }
function createServer(ip, port) {
    return new Promise((resolve, reject) => {
        let isPending = true
        const instance = createHTTPServer(async (request, response) => {
            try {
                const timeout = setTimeout(() => {
                    if (!response.headersSent && response.writable) {
                        response.writeHead(408)
                        response.end("Oops! It seems your response was lost to the void...")
                    }
                }, responseTimeout)
                handleRequest(request, response).then(() => clearTimeout(timeout))
            } catch (err) {
                console.error("Failed to handle request:", err)
                if (!response.headersSent && response.writable) {
                    response.writeHead(500)
                    response.end("Oops! Something broke...")
                }
            }
        })
        instance.on("error", (e) => {
            if (!isPending) return
            isPending = false
            reject(e)
        })
        instance.listen(port, ip, () => {
            if (!isPending) return
            isPending = false
            resolve()
        })
    })
}
function createServer ( ip , port ) { return new Promise ( ( resolve , reject ) => { let isPending = true const instance = createHTTPServer ( async ( request , response ) => { try { const timeout = setTimeout ( ( ) => { if ( ! response . headersSent && response . writable ) { response . writeHead ( 408 ) response . end ( "Oops! It seems your response was lost to the void..." ) } } , responseTimeout ) handleRequest ( request , response ) . then ( ( ) => clearTimeout ( timeout ) ) } catch ( err ) { console . error ( "Failed to handle request:" , err ) if ( ! response . headersSent && response . writable ) { response . writeHead ( 500 ) response . end ( "Oops! Something broke..." ) } } } ) instance . on ( "error" , ( e ) => { if ( ! isPending ) return isPending = false reject ( e ) } ) instance . listen ( port , ip , ( ) => { if ( ! isPending ) return isPending = false resolve ( ) } ) } ) }
Create a HTTP(s) server
 @param {string} ip The IP the server will listen to
 @param {string} port The port the server will listen to
 @param {CertificateObject} certificateConfiguration Possible certificate configuration
 @returns {Promise<void>}
Create a HTTP ( s ) server @param { string } ip The IP the server will listen to @param { string } port The port the server will listen to @param { CertificateObject } certificateConfiguration Possible certificate configuration @returns { Promise<void > }
// TODO: Possible race conditions here?