const paths = require("../paths");
const { isHttps } = require("../config");
const { extractDomainFromUrl, removeTrailingSlashes } = require("../utils");
const { getServerHost, getServerPort } = require("./helpers");

module.exports = {
  publicPath: paths.frontend.dest.relativeUrls.assets,
  headers: {
    "Access-Control-Allow-Origin": "*",
  },
  host: getServerHost(),
  port: getServerPort(),
  https: isHttps,
  // historyApiFallback: true,
  // overlay: true,
  // compress: true,
  noInfo: true,
  quiet: true,
  // stats: "verbose",
  clientLogLevel: "debug",
  hot: true,
  inline: true,
  // disableHostCheck: true, // @see https://github.com/JeffreyWay/laravel-mix/issues/1483
  allowedHosts: [extractDomainFromUrl(process.env.APP_URL)],
  writeToDisk: true, // needed for copy-webpack-plugin and images/media files
  // @see https://webpack.js.org/configuration/dev-server/#devserverproxy
  proxy: {
    "*": {
      target: removeTrailingSlashes(process.env.APP_URL), // target host
      changeOrigin: true, // needed for virtual hosted sites
      // ws: true, // proxy websockets
    },
    // '/api': {
    //   target: process.env.APP_URL,
    //   pathRewrite: {'^/api' : ''}
    // }
  },
};
