import Cors from 'cors';

function initMiddleware(middleware) 
{
	console.log("CORS initMiddleware !!!!");

	return (req, res) => 
		new Promise((resolve, reject) => 
		{
			middleware(req, res, (result) => 
			{
				if (result instanceof Error)
				{
					return reject(result);
				}

				return resolve(result);
			});
		});
}

// Initialize the cors middleware
const cors = initMiddleware(
  // You can read more about the available options here: https://github.com/expressjs/cors#configuration-options
	Cors({
		origin: ["https://localhost:3000", "http://localhost:3000", "localhost", "localhost:3000", "http://localhost", "https://lk-evo.quickcode.ru"], 
		// Only allow requests with GET, POST and OPTIONS
		methods: ['GET', 'POST', 'OPTIONS'],
	})
)

export { cors };