<?php

    require "controller.php";
    
    // $key = bin2hex(bytes(32));
    $key = "se2xy1bknelxn4y8xzxu3trosptip3q5";

    // echo 'Welcomeeeeee';

    header("Access-Control-Allow-Origin: *");
    
    $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
    $uri = explode( '/', $uri );

    // all of our endpoints start with /hucp
    // everything else results in a 404 Not Found
    if ((isset($uri[2]) && $uri[2] != 'hucp') || !isset($uri[3])) {
        
        // header("HTTP/1.1 404 Not Found");
        exit();  
    }
    
    $headers = getallheaders();
    if($headers["authorization"] == $key)
    {
        $controller = new HUCPController($uri[3]);
        $controller->processRequest();
    }


    // echo $uri[2];
    // echo $uri[3];

    


    

?>