Skip to content

Commit 5a74403

Browse files
feat: refactored code
1 parent c86fa47 commit 5a74403

File tree

19 files changed

+240
-196
lines changed

19 files changed

+240
-196
lines changed

.idea/deployment.xml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jsLibraryMappings.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

server/src/main/java/uz/server/config/AuthHandshakeInterceptor.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package uz.server.config;
22

33
import java.util.Map;
4+
45
import org.springframework.http.server.ServerHttpRequest;
56
import org.springframework.http.server.ServerHttpResponse;
67
import org.springframework.stereotype.Component;
@@ -18,11 +19,16 @@ public boolean beforeHandshake(
1819
Map<String, Object> attributes
1920
) {
2021
String authHeader = request.getHeaders().getFirst("Authorization");
22+
String customSubdomain = request.getHeaders().getFirst("Custom-Subdomain");
2123

2224
if (authHeader != null) {
2325
attributes.put("Authorization", authHeader);
2426
}
2527

28+
if (customSubdomain != null){
29+
attributes.put("Custom-Subdomain", customSubdomain);
30+
}
31+
2632
return true;
2733
}
2834

server/src/main/java/uz/server/config/Settings.java

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,77 @@
11
package uz.server.config;
22

33
public class Settings {
4+
public static final String TIMEOUT_HTML = """
5+
<!DOCTYPE html>
6+
<html lang="en">
7+
<head>
8+
<meta charset="UTF-8">
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
10+
<title>Connection Timeout</title>
11+
<style>
12+
body {
13+
margin: 0;
14+
padding: 0;
15+
height: 100vh;
16+
background: linear-gradient(135deg, #f8f9fa, #e9ecef);
17+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
18+
display: flex;
19+
justify-content: center;
20+
align-items: center;
21+
}
22+
23+
.container {
24+
background: #ffffff;
25+
padding: 40px 30px;
26+
border-radius: 12px;
27+
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
28+
text-align: center;
29+
max-width: 400px;
30+
width: 90%;
31+
}
32+
33+
.container h1 {
34+
color: #e74c3c;
35+
margin-bottom: 20px;
36+
font-size: 28px;
37+
}
38+
39+
.container p {
40+
color: #555;
41+
font-size: 16px;
42+
margin-bottom: 15px;
43+
line-height: 1.5;
44+
}
45+
46+
.container a {
47+
display: inline-block;
48+
margin-top: 20px;
49+
padding: 10px 20px;
50+
background-color: #3498db;
51+
color: #fff;
52+
text-decoration: none;
53+
border-radius: 8px;
54+
transition: background-color 0.3s ease;
55+
}
56+
57+
.container a:hover {
58+
background-color: #2980b9;
59+
}
60+
</style>
61+
</head>
62+
<body>
63+
64+
<div class="container">
65+
<h1>Connection Timeout after 45 seconds</h1>
66+
<p>It seems the connection has timed out.</p>
67+
<p>Please check your network settings or try again later.</p>
68+
<a href="https://tarmoqchi.uz">Go to Tarmoqchi</a>
69+
</div>
70+
71+
</body>
72+
</html>
73+
""";
74+
475
public static String NOT_RUNNING_APP_OF_CLIENT_HTML = """
576
<!DOCTYPE html>
677
<html lang="en">

server/src/main/java/uz/server/controller/AuthController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import lombok.RequiredArgsConstructor;
44
import org.springframework.web.bind.annotation.*;
5-
import uz.server.domain.dto.request.AuthRequest;
5+
import uz.server.domain.dto.AuthDTO;
66
import uz.server.service.UserService;
77

88
@RestController
@@ -12,7 +12,7 @@ public class AuthController {
1212
private final UserService userService;
1313

1414
@PostMapping
15-
public void authorizeWithToken(@RequestBody AuthRequest request) {
16-
userService.authorize(request.getToken());
15+
public void authorizeWithToken(@RequestBody AuthDTO request) {
16+
userService.authorizeWithToken(request.token());
1717
}
1818
}

server/src/main/java/uz/server/controller/ForwardController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import uz.server.domain.model.ForwardInfo;
1212
import uz.server.domain.model.Request;
1313
import uz.server.domain.model.Response;
14-
import uz.server.ws.Forwarder;
14+
import uz.server.ws.EventManager;
1515

1616
import java.io.IOException;
1717
import java.util.Enumeration;
@@ -23,7 +23,7 @@
2323
@RestController
2424
@RequiredArgsConstructor
2525
public class ForwardController {
26-
private final Forwarder forwarder;
26+
private final EventManager eventManager;
2727

2828
@RequestMapping(value = "/**", headers = {"Upgrade!=websocket"})
2929
public ResponseEntity<String> handleRequest(
@@ -56,7 +56,7 @@ public ResponseEntity<String> handleRequest(
5656

5757
log.info("Forwarding [{}] request to path: [{}], domain[{}]", method, requestUri, subdomain);
5858

59-
Response response = forwarder.forward(subdomain, Request.builder()
59+
Response response = eventManager.sendRequestToAgent(subdomain, Request.builder()
6060
.forwardInfo(ForwardInfo.builder()
6161
.headers(headers)
6262
.body(body)

server/src/main/java/uz/server/controller/RestExceptionHandler.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@ public ResponseEntity<String> handleBaseException(BaseException e) {
1414
log.error("BaseException: {}", e.getMessage());
1515
return ResponseEntity.badRequest().body(e.getMessage());
1616
}
17+
18+
@ExceptionHandler(Exception.class)
19+
public ResponseEntity<String> handleException(Exception e) {
20+
log.error("Exception: {}", e.getMessage());
21+
return ResponseEntity.internalServerError().body("An unexpected error occurred");
22+
}
1723
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package uz.server.domain.dto;
2+
3+
public record AuthDTO(String token) {
4+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package uz.server.domain.dto;
2+
3+
public record GithubUserDTO(String name, String email, String login, String avatar_url) {}

server/src/main/java/uz/server/domain/dto/request/AuthRequest.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)