const path = require('path');
const os = require('os');
const fs = require('fs');

let configs = {
  type: 'production',
  cookie: {
    path: '/',
    httpOnly: true,
    domain: '.pcoloring.com',
    secure: true,
    maxAge: 1000 * 3600 * 24 * 3, // 30 days.
  },
  sessionName: 'sid',
  mongodbUrl: 'mongodb://coloring:coloring123.@localhost:62701/artsite?authSource=admin',
  host: 'https://art.pcoloring.com',
  resHost: 'https://pcoloring.com',
  STATIC_DIR: path.resolve(os.homedir(), 'www/artsite'),
  sync: 'slave',  // master or slave
  syncUrl: 'mongodb://coloring:coloring123.@hk.jccytech.cn:7881?authSource=admin',
}


let node_env = require('process').env.NODE_ENV || 'production';
try {
  console.log(`Trying to load env spcified configs: ./${node_env}.js`)
  let envConfigs = require(`./${node_env}`);
  configs = Object.assign(configs, envConfigs);

  fs.mkdirSync(configs.STATIC_DIR, { recursive: true });

} catch (err) {
  console.warn(`Load env specific configs failed: ${err}`);
}

console.log(configs);

module.exports = configs;
