"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = require("express");
const stateManager_1 = require("../stateManager");
const cors_1 = __importDefault(require("cors"));
const router = (0, express_1.Router)();
// Enable CORS for all origins for the GET endpoint.
const corsOptions = {
    origin: '*',
};
router.get('/get-active-port', (0, cors_1.default)(corsOptions), (req, res) => {
    const port = stateManager_1.stateManager.getActiveBackendPort();
    res.json({ port });
});
router.post('/set-active-port', (req, res) => {
    const { port } = req.body;
    if (typeof port !== 'number' && port !== null) {
        return res.status(400).json({ error: 'Port must be a number or null.' });
    }
    stateManager_1.stateManager.setActiveBackendPort(port);
    res.status(200).json({ message: 'Active port updated.', port });
});
exports.default = router;
