Skip to content

Commit

Permalink
Fix mobile layout
Browse files Browse the repository at this point in the history
  • Loading branch information
cristipufu committed Aug 26, 2024
1 parent 527ec46 commit 5562007
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 68 deletions.
150 changes: 82 additions & 68 deletions src/Tunnelite.Server/HttpTunnel/HttpAppExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,79 +254,93 @@ await context.Response.WriteAsJsonAsync(new

static async Task TunnelRequestAsync(WebApplication app, HttpContext context, IHubContext<HttpTunnelHub> hubContext, HttpRequestsQueue requestsQueue, HttpTunnelStore tunnelStore, string path, ILogger<Program> logger)
{
try
{
HttpTunnelRequest? tunnel = null;

var subdomain = context.Request.Host.Host.Split('.')[0];

if (subdomain.Equals("localhost", StringComparison.OrdinalIgnoreCase))
{
tunnel = tunnelStore.Tunnels.FirstOrDefault().Value;
}
else if (subdomain.Equals("tunnelite"))
{
var filePath = Path.Combine(app.Environment.WebRootPath, "index.html");

if (File.Exists(filePath))
{
context.Response.ContentType = "text/html";
await context.Response.SendFileAsync(filePath);
}
else
{
context.Response.StatusCode = StatusCodes.Status404NotFound;
await context.Response.WriteAsync("Index page not found");
}
return;
}
else
{
tunnelStore.Tunnels.TryGetValue(subdomain, out tunnel);
}
var filePath = Path.Combine(app.Environment.WebRootPath, "index.html");

if (tunnel == null)
{
context.Response.StatusCode = StatusCodes.Status404NotFound;
await context.Response.WriteAsync(NotFound);
return;
}

if (!tunnelStore.Connections.TryGetValue(tunnel!.ClientId, out var connectionId))
{
context.Response.StatusCode = StatusCodes.Status404NotFound;
await context.Response.WriteAsync(NotFound);
return;
}

var requestId = Guid.NewGuid();

var completionTask = requestsQueue.WaitForCompletionAsync(requestId, context, timeout: TimeSpan.FromSeconds(30), context.RequestAborted);

await hubContext.Clients.Client(connectionId).SendAsync("NewHttpConnection", new HttpConnection
{
RequestId = requestId,
ContentType = context.Request.ContentType,
Method = context.Request.Method,
Path = $"{tunnel.LocalUrl}/{path}{context.Request.QueryString}",
});

await completionTask;
}
catch (TaskCanceledException)
if (File.Exists(filePath))
{
// ignore
context.Response.ContentType = "text/html";
await context.Response.SendFileAsync(filePath);
}
catch (Exception ex)
else
{
if (!context.Response.HasStarted)
{
context.Response.StatusCode = StatusCodes.Status500InternalServerError;
await context.Response.WriteAsync("An error occurred while processing the tunnel.");
}

logger.LogError(ex, "Error processing request tunnel: {Message}", ex.Message);
context.Response.StatusCode = StatusCodes.Status404NotFound;
await context.Response.WriteAsync("Index page not found");
}
return;

//try
//{
// HttpTunnelRequest? tunnel = null;

// var subdomain = context.Request.Host.Host.Split('.')[0];

// if (subdomain.Equals("localhost", StringComparison.OrdinalIgnoreCase))
// {
// tunnel = tunnelStore.Tunnels.FirstOrDefault().Value;
// }
// else if (subdomain.Equals("tunnelite"))
// {
// var filePath = Path.Combine(app.Environment.WebRootPath, "index.html");

// if (File.Exists(filePath))
// {
// context.Response.ContentType = "text/html";
// await context.Response.SendFileAsync(filePath);
// }
// else
// {
// context.Response.StatusCode = StatusCodes.Status404NotFound;
// await context.Response.WriteAsync("Index page not found");
// }
// return;
// }
// else
// {
// tunnelStore.Tunnels.TryGetValue(subdomain, out tunnel);
// }

// if (tunnel == null)
// {
// context.Response.StatusCode = StatusCodes.Status404NotFound;
// await context.Response.WriteAsync(NotFound);
// return;
// }

// if (!tunnelStore.Connections.TryGetValue(tunnel!.ClientId, out var connectionId))
// {
// context.Response.StatusCode = StatusCodes.Status404NotFound;
// await context.Response.WriteAsync(NotFound);
// return;
// }

// var requestId = Guid.NewGuid();

// var completionTask = requestsQueue.WaitForCompletionAsync(requestId, context, timeout: TimeSpan.FromSeconds(30), context.RequestAborted);

// await hubContext.Clients.Client(connectionId).SendAsync("NewHttpConnection", new HttpConnection
// {
// RequestId = requestId,
// ContentType = context.Request.ContentType,
// Method = context.Request.Method,
// Path = $"{tunnel.LocalUrl}/{path}{context.Request.QueryString}",
// });

// await completionTask;
//}
//catch (TaskCanceledException)
//{
// // ignore
//}
//catch (Exception ex)
//{
// if (!context.Response.HasStarted)
// {
// context.Response.StatusCode = StatusCodes.Status500InternalServerError;
// await context.Response.WriteAsync("An error occurred while processing the tunnel.");
// }

// logger.LogError(ex, "Error processing request tunnel: {Message}", ex.Message);
//}
}

static string RandomSubdomain(int length = 8)
Expand Down
75 changes: 75 additions & 0 deletions src/Tunnelite.Server/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,81 @@
.copy-notification.show {
opacity: 1;
}

@media (max-width: 768px) {
.container {
padding: 0 1.5rem;
}

.hero {
padding: 40px 0;
}

h1 {
font-size: 36px;
}

.subtitle {
font-size: 20px;
}

.features {
grid-template-columns: 1fr;
gap: 20px;
}

.installation, .usage, .self-hosting {
padding: 20px;
}

pre {
font-size: 14px;
padding: 15px;
}
}

@media (max-width: 480px) {
.nav-links {
flex-direction: column;
gap: 0.5rem;
}

.nav-links a {
padding: 0.5rem 0;
}

h1 {
font-size: 28px;
}

.subtitle {
font-size: 18px;
}

.cta-button {
padding: 10px 20px;
font-size: 16px;
}
}

@media (max-width: 768px) {

header {
display: none;
}
.copy-button {
display: block;
width: 100%;
margin-top: 10px;
}

.copy-notification {
bottom: 10px;
right: 10px;
left: 10px;
text-align: center;
}
}
</style>
</head>
<body>
Expand Down

0 comments on commit 5562007

Please sign in to comment.