const path = require("path");
const merge = require('webpack-merge')
const common = require('./webpack.common.js');
const webpack = require('webpack');
const config = require('config');

const base = config.get("basePath");

const proxy = {
//      "/photos/api/*": "http://localhost:8123/",
}

proxy[`${base}/`] = {
  target: "http://localhost:8766",
  bypass: function(req, res, proxyOptions) {
    console.log(req.url);
    if (req.url.match(new RegExp(base.replace(/\//g, "\\/") + "\/identities[/?]?"))) {
      return 'index.html';
    } else {
      return null;
    }
  }
};

module.exports = merge(common, {
  mode: "development",
  devServer: {
    contentBase: path.join(__dirname, "/"),
    port: 8765,
    publicPath: `http://localhost:8765${base}/dist/`,
    hotOnly: true,
    disableHostCheck: true,
    historyApiFallback: true,
    proxy: proxy
  },
  plugins: [new webpack.HotModuleReplacementPlugin()]
});

