// config/https.js
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0

'use strict';

if (process.env.HTTPS_ENABLE === 'enabled') {
  if (!process.env.HTTPS_SSL_CRT) {
    throw new Error('Must specify HTTPS_SSL_CRT in .env (HTTPS is enabled)');
  }
  if (!process.env.HTTPS_SSL_KEY) {
    throw new Error('Must specify HTTPS_SSL_KEY in .env (HTTPS is enabled)');
  }
}

module.exports = {
  enabled: process.env.HTTPS_ENABLE === 'enabled',
  scheme: 'https',
  address: process.env.HTTPS_BIND_ADDRESS || "127.0.0.1",
  port: parseInt(process.env.HTTPS_BIND_PORT || "3400", 10),
  options: {
    crt: process.env.HTTPS_SSL_CRT,
    key: process.env.HTTPS_SSL_KEY,
  },
};