#!/usr/bin/env node

/**
 * Bud file for site.
 * Executing this file renders nginx virtual host configurations.
 *
 * Generated by {{generator}} on {{today}},
 * from a template provided by {{ pkg.name }}.
 *
 * @see https://github.com/coz-repo/coz
 */

'use strict'

const apemanBudNginx = require('apeman-bud-nginx')
const apeman = require('apeman')
const path = require('path')

const { pkg, env, nginxMountDir } = apeman.ctx(__dirname)

let domain = env('domain')
let port = env('port')
let public_ = env('public')
let error = env('error')

let _resolvePath = pathname => path.resolve(nginxMountDir, pathname)

module.exports = Object.keys(domain).map((key) => {
  return apemanBudNginx({
    /**
     * Domain of the virtual host.
     */
    domain: domain[key],
    /**
     * Application name.
     */
    name: key,
    /**
     * Ports to proxy.
     */
    port: port[key],
    /**
     * Path of public directory on the container.
     */
    public: [].concat(public_[key]).map(_resolvePath),
    /**
     *  Path of error files directory on the container.
     */
    error: [].concat(error[key]).map(_resolvePath),
    /**
     * Host name of destination server.
     * Use the node container hostname, which is written in /etc/hosts on the container by Docker network.
     */
    server: apeman.dply.nameDply('node', pkg)
  })
})

{{{read _render}}}
