the middle of the idiots
This commit is contained in:
		@@ -82,19 +82,7 @@ class Application
 | 
			
		||||
            return $response->withHeader('Content-Type', 'application/json');
 | 
			
		||||
        });
 | 
			
		||||
        
 | 
			
		||||
        // Tenant-specific job positions routes
 | 
			
		||||
        $this->app->get('/positions', function (Request $request, Response $response, array $args) {
 | 
			
		||||
            $tenant = $request->getAttribute('tenant');
 | 
			
		||||
            
 | 
			
		||||
            // For now, return a placeholder response
 | 
			
		||||
            $data = [
 | 
			
		||||
                'tenant' => $tenant['name'],
 | 
			
		||||
                'positions' => [] // Will be populated later
 | 
			
		||||
            ];
 | 
			
		||||
            
 | 
			
		||||
            $response->getBody()->write(json_encode($data));
 | 
			
		||||
            return $response->withHeader('Content-Type', 'application/json');
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        
 | 
			
		||||
        // Tenant-specific user authentication routes
 | 
			
		||||
        $this->app->post('/auth/login', function (Request $request, Response $response, array $args) {
 | 
			
		||||
@@ -150,9 +138,9 @@ class Application
 | 
			
		||||
        // Job provider routes
 | 
			
		||||
        $this->app->post('/positions', [\App\Controllers\JobProviderController::class, 'createPosition']);
 | 
			
		||||
        $this->app->put('/positions/{id}', [\App\Controllers\JobProviderController::class, 'updatePosition']);
 | 
			
		||||
        $this->delete('/positions/{id}', [\App\Controllers\JobProviderController::class, 'deletePosition']);
 | 
			
		||||
        $this->app->delete('/positions/{id}', [\App\Controllers\JobProviderController::class, 'deletePosition']);
 | 
			
		||||
        $this->app->get('/positions/{id}/applications', [\App\Controllers\JobProviderController::class, 'getApplicationsForPosition']);
 | 
			
		||||
        $this->put('/applications/{id}', [\App\Controllers\JobProviderController::class, 'updateApplicationStatus']);
 | 
			
		||||
        $this->app->put('/applications/{id}', [\App\Controllers\JobProviderController::class, 'updateApplicationStatus']);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function run(): void
 | 
			
		||||
 
 | 
			
		||||
@@ -25,8 +25,14 @@ class TenantMiddleware implements MiddlewareInterface
 | 
			
		||||
        $tenantModel = new Tenant();
 | 
			
		||||
        $tenant = $tenantModel->findBySubdomain($subdomain);
 | 
			
		||||
        
 | 
			
		||||
        // If tenant not found, use default tenant for development
 | 
			
		||||
        if (!$tenant) {
 | 
			
		||||
            // Handle case where tenant doesn't exist
 | 
			
		||||
            // Try to get the default tenant
 | 
			
		||||
            $tenant = $tenantModel->findBySubdomain('tsys');
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        if (!$tenant) {
 | 
			
		||||
            // Handle case where even default tenant doesn't exist
 | 
			
		||||
            $response = new \Slim\Psr7\Response();
 | 
			
		||||
            $response->getBody()->write(json_encode(['error' => 'Tenant not found']));
 | 
			
		||||
            return $response->withStatus(404)->withHeader('Content-Type', 'application/json');
 | 
			
		||||
@@ -40,14 +46,27 @@ class TenantMiddleware implements MiddlewareInterface
 | 
			
		||||
    
 | 
			
		||||
    private function extractSubdomain(string $host): ?string
 | 
			
		||||
    {
 | 
			
		||||
        $hostParts = explode('.', $host);
 | 
			
		||||
        // Remove port if present
 | 
			
		||||
        $host = preg_replace('/:\d+$/', '', $host);
 | 
			
		||||
        
 | 
			
		||||
        // For localhost or IP addresses, return as is
 | 
			
		||||
        if (count($hostParts) === 1 || filter_var($hostParts[0], FILTER_VALIDATE_IP)) {
 | 
			
		||||
            return $host;
 | 
			
		||||
        // For localhost, return null to trigger default behavior
 | 
			
		||||
        if ($host === 'localhost') {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        // Return the first part (subdomain)
 | 
			
		||||
        return $hostParts[0];
 | 
			
		||||
        $hostParts = explode('.', $host);
 | 
			
		||||
        
 | 
			
		||||
        // For IP addresses, return null to trigger default behavior
 | 
			
		||||
        if (filter_var($hostParts[0], FILTER_VALIDATE_IP)) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        // Return the first part (subdomain) if we have multiple parts
 | 
			
		||||
        if (count($hostParts) > 1) {
 | 
			
		||||
            return $hostParts[0];
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        // For single part hosts, return null to trigger default behavior
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user