Skip to content

Commit

Permalink
Solara
Browse files Browse the repository at this point in the history
  • Loading branch information
IdeaS0ft committed Sep 5, 2024
1 parent faa17a4 commit ffd0642
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 37 deletions.
16 changes: 15 additions & 1 deletion solara/lib/core/dashboard/dashboard_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,23 @@ def create_server
@server = WEBrick::HTTPServer.new(
Port: @port,
DocumentRoot: @root,
DirectoryIndex: ['index.html'],
Logger: logger
)

@server.mount_proc '/' do |req, res|
path = req.path == '/' ? '/index.html' : req.path
file_path = File.join(@root, path)

if File.exist?(file_path) && !File.directory?(file_path)
res.body = File.read(file_path)
res['Content-Type'] = WEBrick::HTTPUtils.mime_type(file_path, WEBrick::HTTPUtils::DefaultMimeTypes)
else
res.status = 404
end

# Add the source=local parameter to all responses
res['Location'] = "#{req.path}?source=local" if res.status == 302
end
rescue StandardError => e
Solara.logger.failure("Error creating server: #{e.message}")
exit(1)
Expand Down
89 changes: 53 additions & 36 deletions solara/lib/core/dashboard/index.html
Original file line number Diff line number Diff line change
@@ -1,41 +1,58 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Redirecting...</title>
<style>
body, html {
height: 100%;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
background-color: #f0f0f0;
}
.container {
text-align: center;
}
img {
max-width: 50%;
max-height: 80vh;
object-fit: contain;
}
</style>
<script>
fetch('/redirect')
.then(response => response.json())
.then(data => {
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Redirecting...</title>
<style>
body, html {
height: 100%;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
background-color: #f0f0f0;
}
.container {
text-align: center;
}
img {
max-width: 50%;
max-height: 80vh;
object-fit: contain;
}
</style>
<script>
// Function to get query parameters
function getQueryParameter(name) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(name);
}

// Get the source from the query parameter, default to 'local'
const source = getQueryParameter('source') || 'local';

if (source === 'local') {
fetch('/redirect')
.then(response => response.json())
.then(data => {
setTimeout(() => {
window.location.href = data.redirect_url;
}, 500);
})
.catch(error => console.error('Error:', error));
} else if (source === 'remote') {
setTimeout(() => {
window.location.href = data.redirect_url;
window.location.href = 'brands/brands.html?source=remote';
}, 500);
})
.catch(error => console.error('Error:', error));
</script>
</head>
<body>
<div class="container">
<img src="solara.png" alt="Logo Image">
</div>
</body>
} else {
console.error('Invalid source parameter');
}
</script>
</head>
<body>
<div class="container">
<img src="solara.png" alt="Logo Image">
</div>
</body>
</html>

0 comments on commit ffd0642

Please sign in to comment.