Repository: digitalocean/nginxconfig.io
File: src/nginxconfig/generators/conf/website.conf.js (JavaScript)

Code before:
            `[${domain.server.listenIpv6.computed}]:443 ssl${domain.https.http2.computed ? ' http2' : ''}`]);

    return config;
};

const httpListen = domain => {
    const config = [];

    // Not HTTPS
    config.push(['listen', `${domain.server.listenIpv4.computed === '*' ? '' : `${domain.server.listenIpv4.computed}:`}80`]);

    // v6
    if (domain.server.listenIpv6.computed)
        config.push(['listen', `[${domain.server.listenIpv6.computed}]:80`]);

    return config;
};

const listenConfig = domain => {
    if (domain.https.https.computed) return httpsListen(domain);
    return httpListen(domain);
};


function httpRedirectConfig(domain, global, domainName, redirectDomain)
{
    // Build the server config on its own before adding it to the parent config
    const config = [];

    config.push(...httpListen(domain));
    config.push(['server_name', domainName]);

    if (domain.https.certType.computed === 'letsEncrypt') {
        // Let's encrypt

        if (global.tools.modularizedStructure.computed) {
            // Modularized
            config.push(['include', 'nginxconfig.io/letsencrypt.conf']);
        } else {
            // Unified
            config.push(...Object.entries(letsEncryptConf(global)));
        }

        config.push(['location /', {
            return: `301 https://${redirectDomain ? redirectDomain : domainName}$request_uri`,
        }]);
    } else {
        // Custom cert
        config.push(['return', `301 https://${redirectDomain ? redirectDomain : domainName}$request_uri`]);
    }


Review comment (suggestion):
```suggestion
const httpRedirectConfig = (domain, global, domainName, redirectDomain) => {
```
Arrow function, please :)

Code after:
            `[${domain.server.listenIpv6.computed}]:443 ssl${domain.https.http2.computed ? ' http2' : ''}`]);

    return config;
};

const httpListen = domain => {
    const config = [];

    // Not HTTPS
    config.push(['listen', `${domain.server.listenIpv4.computed === '*' ? '' : `${domain.server.listenIpv4.computed}:`}80`]);

    // v6
    if (domain.server.listenIpv6.computed)
        config.push(['listen', `[${domain.server.listenIpv6.computed}]:80`]);

    return config;
};

const listenConfig = domain => {
    if (domain.https.https.computed) return httpsListen(domain);
    return httpListen(domain);
};


const httpRedirectConfig = (domain, global, domainName, redirectDomain) => {
    // Build the server config on its own before adding it to the parent config
    const config = [];

    config.push(...httpListen(domain));
    config.push(['server_name', domainName]);

    if (domain.https.certType.computed === 'letsEncrypt') {
        // Let's encrypt

        if (global.tools.modularizedStructure.computed) {
            // Modularized
            config.push(['include', 'nginxconfig.io/letsencrypt.conf']);
        } else {
            // Unified
            config.push(...Object.entries(letsEncryptConf(global)));
        }

        config.push(['location /', {
            return: `301 https://${redirectDomain ? redirectDomain : domainName}$request_uri`,
        }]);
    } else {
        // Custom cert
        config.push(['return', `301 https://${redirectDomain ? redirectDomain : domainName}$request_uri`]);
    }

    return config;