let path = require('path');

const mockApis = require('./configurations/mock.json').sdcConfig;
const proxy = require('http-proxy-middleware');
const devPort = 9000;
const fePort = 8181;
const loclahost = "192.168.33.10"; // "localhost"

module.exports = function(env) {

	// Set default role
	if (!env) {
		env = {
			role: "designer"
		};
	}
	console.log("Starting dev server with role: " + env.role);

	const ServerConfig = {
		port: devPort,
		historyApiFallback: true,
		inline: true,
		stats: {
			colors: true,
			exclude: ['node_modules']
		},
		setup: server => {
		let userType = mockApis.userTypes[env.role];

	let middlewares = [
		(req, res, next) => {
		res.cookie(mockApis.cookie.userIdSuffix, req.headers[mockApis.cookie.userIdSuffix] || userType.userId);
	res.cookie(mockApis.cookie.userEmail, req.headers[mockApis.cookie.userEmail] || userType.email);
	res.cookie(mockApis.cookie.userFirstName, req.headers[mockApis.cookie.userFirstName] || userType.firstName);
	res.cookie(mockApis.cookie.userLastName, req.headers[mockApis.cookie.userLastName] || userType.lastName);
	next();
}
];

	// Redirect all '/sdc1/feProxy/rest' to feHost
	middlewares.push(
		proxy(['/sdc1/feProxy/rest'],{
                    target: 'http://' + loclahost + ':' + fePort,
			changeOrigin: true,
			secure: false
		}));

	// Redirect all '/sdc1/rest' to feHost
    middlewares.push(
        proxy(['/sdc1/rest'],{
            target: 'http://' + loclahost + ':' + fePort,
            changeOrigin: true,
            secure: false
        }));

	// Redirect dcae urls to feHost
	middlewares.push(
		proxy(['/dcae','/sdc1/feProxy/dcae-api'],{
                    target: 'http://' + loclahost + ':' + fePort,
			changeOrigin: true,
			secure: false,
			onProxyRes: (proxyRes, req, res) => {
			let setCookie = proxyRes.headers['set-cookie'];
	if (setCookie) {
		setCookie[0] = setCookie[0].replace(/\bSecure\b(; )?/, '');
	}
}
}));

	// Redirect onboarding urls to feHost
	middlewares.push(
		proxy(['/onboarding','/sdc1/feProxy/onboarding-api'],{
                    target: 'http://' + loclahost + ':' + fePort,
			changeOrigin: true,
			secure: false,
			onProxyRes: (proxyRes, req, res) => {
			let setCookie = proxyRes.headers['set-cookie'];
	if (setCookie) {
		setCookie[0] = setCookie[0].replace(/\bSecure\b(; )?/, '');
	}
}
}));

	server.use(middlewares);
}
};

	return ServerConfig;
}
