fix(domains): provision routes when domains are linked
Build and publish Docker image / build-and-publish (push) Successful in 10s
Build and publish Docker image / build-and-publish (push) Successful in 10s
This commit is contained in:
1 parent
8cb6820bea
commit
9822e43592
3 files changed
+131
-154
No files matched your search
+19
-3
@@ -112,12 +112,22 @@ def create_domain_api():
|
||||
if not domain_manager:
|
||||
return jsonify({'error': 'Domain service not available'}), 503
|
||||
|
||||
data = request.get_json()
|
||||
data = request.get_json(silent=True) or {}
|
||||
subdomain = '' if data.get('useUsernameDomain') is True else data.get('subdomain')
|
||||
server_id = data.get('serverId')
|
||||
server_id = data.get('serverId') or None
|
||||
|
||||
if subdomain is None:
|
||||
return jsonify({'error': 'Subdomain name required'}), 400
|
||||
if server_id and not isinstance(server_id, str):
|
||||
return jsonify({'error': 'Server ID must be a string'}), 400
|
||||
|
||||
server = None
|
||||
if server_id:
|
||||
server = get_server_by_id(server_id)
|
||||
if not server or server.get('owner_id') != user['id']:
|
||||
return jsonify({'error': 'Server not found or access denied'}), 404
|
||||
if server.get('type') not in ('website', 'vps'):
|
||||
return jsonify({'error': 'Domain can only be linked to Website or VPS servers'}), 400
|
||||
|
||||
# Check if subdomain is available
|
||||
availability_result = domain_manager.check_domain_availability(subdomain, user['username'])
|
||||
@@ -143,10 +153,16 @@ def create_domain_api():
|
||||
db_domain = create_domain_record(domain_record)
|
||||
|
||||
if db_domain:
|
||||
routing_ready = not server_id or db_domain.get('server_id') == server_id
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'domain': db_domain,
|
||||
'message': result['message']
|
||||
'message': result['message'] if routing_ready else (
|
||||
'Domain created, but routing could not be provisioned. '
|
||||
'It remains unlinked; retry linking it after checking Kubernetes.'
|
||||
),
|
||||
'routingReady': routing_ready
|
||||
}), 201
|
||||
else:
|
||||
return jsonify({'error': 'Domain created in DNS but failed to save to database'}), 500
|
||||
|
||||
Reference in new issue
Block a user