Added Various API Functionality

This commit is contained in:
2025-05-10 16:23:32 -06:00
parent 6ff4170894
commit bce39d355f
14 changed files with 538 additions and 1 deletions

View File

@ -4,8 +4,10 @@ import eventlet
# Monkey-patch stdlib for cooperative sockets
eventlet.monkey_patch()
from flask import Flask, request, jsonify, Response, send_from_directory
import requests
from flask import Flask, request, jsonify, Response, send_from_directory, make_response
from flask_socketio import SocketIO, emit
from flask_cors import CORS
import time
import os # To Read Production ReactJS Server Folder
@ -22,6 +24,9 @@ app = Flask(
static_url_path=''
)
# Enable CORS on All Routes
CORS(app)
socketio = SocketIO(
app,
cors_allowed_origins="*",
@ -108,6 +113,32 @@ def provision_agent():
socketio.emit("agent_config", config)
return jsonify({"status": "provisioned", "roles": roles})
# ---------------------------------------------
# Borealis External API Proxy Endpoint
# ---------------------------------------------
@app.route("/api/proxy", methods=["GET", "POST", "OPTIONS"])
def proxy():
target = request.args.get("url")
if not target:
return {"error": "Missing ?url="}, 400
# Forward method, headers, body
upstream = requests.request(
method = request.method,
url = target,
headers = {k:v for k,v in request.headers if k.lower() != "host"},
data = request.get_data(),
timeout = 10
)
excluded = ["content-encoding","content-length","transfer-encoding","connection"]
headers = [(k,v) for k,v in upstream.raw.headers.items() if k.lower() not in excluded]
resp = make_response(upstream.content, upstream.status_code)
for k,v in headers:
resp.headers[k] = v
return resp
# ---------------------------------------------
# Live Screenshot Viewer for Debugging
# ---------------------------------------------